Name: dfC67450 Date: 02/28/2000
java.net.URLEncoder.encode(String) works wrong when external encoding is set
Javadoc states:
To convert a String, each character is examined in turn:
The ASCII characters 'a' through 'z', 'A' through 'Z',
'0' through '9', and ".", "-", "*", "_" remain the same.
The space character ' ' is converted into a plus sign '+'.
All other characters are converted into the 3-character string
"%xy", where xy is the two-digit hexadecimal representation of
the lower 8-bits of the character.
In the reference implementation string argument is converted to the external
encoding before hex conversion. This feature is undocumented.
Here is the test demonstrating the bug:
---------------------------------------------
import java.net.*;
public class Test {
public static void main (String args[]){
String s = "\u00AA";
String encoded = URLEncoder.encode(s);
System.out.println("encoded : " + encoded);
System.out.println("expected : %AA");
if ("%AA".equals(encoded))
System.out.println("Test passed");
else
System.out.println("Test failed");
}
}
------------- output ---------
#>java Test
encoded : %AA
expected : %AA
Test passed
#> java -Dfile.encoding=koi8-r Test
encoded : %3F
expected : %AA
Test failed
----------------------------------------------------------
======================================================================