Does Class URLDecoder.decode handle double encoding?

1.1k views Asked by At

I am trying to debug a flaky Java application. I can't (easily) debug it in the only way I would know how - by putting a log statement in it and re-compiling. Then checking the logs.

(I don't have access to a reliable set of source code). And I'm not a Java developer.

The actual question:

If I did this:

str = URLDecoder.decode("%25C3%2596");

What would be in str?

Would it realize that this is double-encoded and handle that i.e. turn it into %C3%96 - and then decode that? (Which decodes into a German Umlaut).

Thanks

--Justin Wyllie

2

There are 2 answers

0
Ceiling Gecko On

From the Java API URLDecoder:

A sequence of the form "%xy" will be treated as representing a byte where xy is the two-digit hexadecimal representation of the 8 bits.

So my guess would be - most likely not.

You could however call the decode method twice.

str = URLDecoder.decode(URLDecoder.decode("%25C3%2596"));
0
McDowell On
str = URLDecoder.decode("%25C3%2596");

The result of this operation is system-dependent (the reason the method is deprecated.)

The result of this call:

str = URLDecoder.decode("%25C3%2596", "UTF-8");

...would be %C3%96 which is Ö in percent-encoded UTF-8. The API does not try to recursively decode any percent-signs.