JDK-4316925 : URLEncoder.encode(String) works wrong when external encoding is set
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 1.3.0,1.4.0
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic,solaris_2.6
  • CPU: generic,sparc
  • Submitted: 2000-02-28
  • Updated: 2000-04-28
  • Resolved: 2000-04-28
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
1.4.0 betaFixed
Related Reports
Duplicate :  
Relates :  
Description

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

----------------------------------------------------------
======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: merlin-beta FIXED IN: merlin-beta INTEGRATED IN: merlin-beta
14-06-2004

EVALUATION mayank.upadhyay@eng 2000-02-28 See bugid 4257115.
28-02-2000