I have a hash key in one of my query params which can have + char with other special chars. The issue is when this URL is getting decoded URLDecoder converts + char into space. Is there a way we can enforce URLDecoder not to convert '+' into space.
html.” Spaces and other characters that aren't allowed in a URL must be encoded using a percent sign and the hexadecimal value assigned to the character in the ISO-Latin character set. A space is assigned number 32, which is 20 in hexadecimal.
decode. Decodes a application/x-www-form-urlencoded string using a specific encoding scheme. The supplied encoding is used to determine what characters are represented by any consecutive sequences of the form " %xy ".
%2B in url is translated to space, should be + (plus sign)?
Note that Java's URLEncoder class encodes space character( " " ) into a + sign. This is contrary to other languages like Javascript that encode space character into %20 .
Do this on your string before decoding:
String plusEncoded = yourString.replaceAll("\\+", "%2b")
The decoder will then show +
where it should've been
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With