0

I was trying to decode URL encoded post body and came across this problem.

I was using this method to decode (it decodes multiple encoded urls too) :

public static String decodeUrl(String url)
    {
        try {
            String prevURL="";
            String decodeURL=url;
            while(!prevURL.equals(decodeURL))
            {
                prevURL=decodeURL;
                decodeURL= URLDecoder.decode( decodeURL, "UTF-8" );
            }
            return decodeURL;
        } catch (UnsupportedEncodingException e) {
            return "Issue while decoding" +e.getMessage();
        }
    }

When the input url was "a%20%2B%20b%20%3D%3D%2013%25!" , the control somehow doens't show up after line decodeURL = when debugging . No exceptions are raised too.

The issue is that control doesn't go beyond the line"decodeURL" .

What might be causing the issue ? Please use debugger to hopefully mimic this problem.

1
  • what do you mean with "control" ? Commented Aug 8, 2018 at 19:01

1 Answer 1

2

Just tested it on Java 8u151. This throws an IllegalArgumentException on the second spin of the loop: "URLDecoder: Incomplete trailing escape (%) pattern". That's because after the first decoding you have "a + b == 13%!", and during the second decoding that % is supposed to introduce an encoding sequence but it does not. I think that's the expected behaviour, even if the standard library of other languages does not agree. Python 3.6 for example:

>>> from urllib.parse import unquote
>>> result = unquote('a%20%2B%20b%20%3D%3D%2013%25!')
>>> result
'a + b == 13%!'
>>> unquote(result)
'a + b == 13%!'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.