Skip to content

Instantly share code, notes, and snippets.

@viclm
Last active May 8, 2018 10:21
Show Gist options
  • Save viclm/0285ec0d3e00dffb8801c23e5f77529a to your computer and use it in GitHub Desktop.
Save viclm/0285ec0d3e00dffb8801c23e5f77529a to your computer and use it in GitHub Desktop.
/*
MDC on encodeURIComponent():
literal characters (regex representation): [-a-zA-Z0-9._*~'()!]
Java 1.5.0 documentation on URLEncoder:
literal characters (regex representation): [-a-zA-Z0-9._*]
the space character " " is converted into a plus sign "+".
*/
const rnoEncodeChar = /%20|~|'|\(|\)|!/g;
const NoEncodeCharMap = {
'%20': '+',
'~': '%7E',
'\'': '%27',
'(': '%28',
')': '%29',
'!': '%21',
};
function encodeURIComponentJava(str) {
return encodeURIComponent(str).replace(rnoEncodeChar, function (s) {
return NoEncodeCharMap[s];
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment