2

I have an environment where strings are percent encoded by Actionscript escape() function and then passed to Java for decoding.

I have for example a test string "m é".
It is passed to Actionscript escape() that outputs "m%20%E9"
When I try to decode it with Java:

URLDecoder.decode("m%20%E9", "UTF-8")

The result is:

"m ?"

%E9 seems the unicode point for "é" character, but it is not quite understood by Java decode.
Is there a way to decode in Java the strings encoded by Actionscript escape()? What escape format do these function use since they seem to be different?

Thanks in advance for any help,
Paolo

1 Answer 1

10

m%20%E9 is not UTF-8. That's easy to see because any character outside of the ASCII range (i.e. 0-127) would need at least 2 bytes in UTF-8. Since %20 is space, that leaves only %E9 for é.

And é is in fact U+00E9. The encoding maps 1:1 to Unicode in the lower 255 characters is ISO-8859-1.

So the correct way to decode this would be this:

URLDecoder.decode("m%20%E9", "ISO-8859-1")
Sign up to request clarification or add additional context in comments.

3 Comments

Hi Joachim, thanks for your help but your code produces for me the same result "m ?" :(
@Paull: for me it produces "m é", as expected.
you are right, I tried in a new application and it works perfectly. There must be something wrong in my setup. Thanks again!

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.