I have a string in JS side which is url.QueryEscape
d.
Spaces were replaced with + sign by url.QueryEscape
. They don't get converted back to space in decodeURIComponent
. Should I manually do a string replace all + with space? What is the right way to decode it?
One simple method is to replace all the +
characters with spaces prior to decoding. For example:
decodeURIComponent("%2f+%2b".replace(/\+/g, " "))
will correctly decode the string to "/ +"
. Note that it is necessary to perform the replacement prior to decoding, since there could be encoded +
characters in the string.