Last active
May 8, 2018 10:21
-
-
Save viclm/0285ec0d3e00dffb8801c23e5f77529a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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