Is there any method that fully decodes a String ? For example I have

monta%25C3%25B1a , if I use UrlDecoder.decode method ONCE : it returns monta%C3%B1a and if I decodify AGAIN , it finally returns montaña (that is the fully decodified string).Is there any method or library in Java that achieves this result?

  • 2
    No there's nothing like that, because you're not supposed to URLEncode twice. It's up to you to implement something like that, or preferably change the code that performs this double encoding. – Kayaman Sep 17 at 11:09
monta  %  C3  %  B1a    which has a UTF-8 multi-byte sequence
monta       ñ      a

It is important to decode with the same Charset as it was encoded. Evidently it was URL encoded twice, first into UTF-8, and then % was still encoded once.

Twice doing the encoding should be repaired, as otherwise an incomprehensible patch remains:

s = URLDecoder.decode(s, StandardCharsets.UTF_8);
s = URLDecoder.decode(s, StandardCharsets.UTF_8);

Your Answer

