JDK-4488606 : URLDecoder.decode() should not do charset conversion
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 1.2.2_08
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: solaris_2.6
  • CPU: sparc
  • Submitted: 2001-08-06
  • Updated: 2001-08-07
  • Resolved: 2001-08-07
Related Reports
Duplicate :  
Relates :  
Description
decode() has this section at the end of it:

        // Undo conversion to external encoding
        String result = sb.toString();
        byte[] inputBytes = result.getBytes("8859_1");
        return new String(inputBytes);

but URLEncoder.encode() OutputStreamWriter() uses the default constructor
so it does not specify what the charset used is, so it is not necessarily
have to be 8859_1. Since URLEncoder.encode() is 'supposedly' just taking
the low 8bits and encoding them, and this is just reversing that, then
this step is not needed. The end of this function should just be:

        return sb.toString();


Comments
SUGGESTED FIX The end of this function should just be: return sb.toString(); with no charset conversion. (Thanks to Tom Mueller.)
11-06-2004

EVALUATION In JDK1.4 (J2SE 1.4), URLEncoder and URLDecoder APIs have been redesigned and the methods reimplemented. The problems mentioned by the description should go away. Please verify this. yingxian.wang@eng 2001-08-07 The offending code has been removed in 1.4, as a consequence of the fix for 4257115. I'll close as a dup of that bug. michael.mcmahon@ireland 2001-08-07
07-08-2001