0

I am facing one issue while decoding data like '1º' using URLCodec of Apache commons. It is decoded as '1?'.

Is there any solution for this issue?

Before i have tried using below code :

String decodedData = new URLCodec().decode(data, "ISO-8859-1");

I have tried using below code also. But it didn't helped.

String decodedData = new URLCodec().decode(data, "UTF-8");

D Vekaria
  • 140
  • 3
  • 11

1 Answers1

2

According to the documentation, the decode function is to take in a standard URL, and decode the values out of it. A www-form-urlencoded encoded value can only have a specified set of ASCII values in it.

Your question suggests that you are submitting a URL value with characters that are not in the valid range for www-form-urlencoded.

The answer then is: I believe you are trying to decode a value that is not properly www-form-urlencoded and that is the source of your problem.

The value you gave: 1º which is a numeral 1, followed by a 'Masculine ordinal indicator' (assuming that nothing got distorted editing this StackOverflow entry). The Masculine ordinal indicator is at decimal value 186, which is hex value 00BA.

Assuming you start with that value as unencoded data, then the www-form-urlencoded value for this two character sequence will depend upon whether you use UTF-8 or ISO-8859-1. Here are the encoded versions of each:

unencoded value:                           1º
www-form-urlencoded using ISO-8859-1 is:   1%BA
www-form-urlencoded using UTF-8 is:        1%C2%BA

If you take the encoded form, and pass it through the decoder, you should get the unencoded form back. However, there is no definition of what happens when you take the unencoded version, and attempt to decode it. Since it is not defined, the actual implementation and the actual result may vary. It probably should be throwing an exception as an invalid encoding, but that is not guaranteed either.

AgilePro
  • 5,588
  • 4
  • 33
  • 56
  • Thank you for the answer. This character was working before. Now it is creating problem in decodeing the form data. – D Vekaria Feb 14 '13 at 09:33