Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

URLDecoder is converting '+' into space

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.

like image 755
Nighthacks Avatar asked Apr 12 '17 17:04

Nighthacks


People also ask

Why is %20 a 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.

What does Urldecoder decode do?

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 ".

What does %2B mean in URL?

%2B in url is translated to space, should be + (plus sign)?

How do you encode a space in Java?

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 .


1 Answers

Do this on your string before decoding:

String plusEncoded = yourString.replaceAll("\\+", "%2b")

The decoder will then show + where it should've been

like image 56
mehulmpt Avatar answered Sep 29 '22 09:09

mehulmpt