Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4488596

URLEncoder.encode() does not always take the low 8 bits of character

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 1.2.2_08
    • core-libs
    • None
    • sparc
    • solaris_2.6

      javadocs say '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.'

      Problem was seen trying to round trip Arabic text on a Sol8 system with a
      default LANG of 'ar' (8859-6) through UTF-8 to URLEncoded and then all the
      way back. The URLEncode decode was mangling the encoded text due to the
      interaction with the non-english default charset.

      But the code is:

      OutputStreamWriter writer = new OutputStreamWriter(buf);

      which uses the default encoding of the system property file.encoding to do
      the encoding. If the char needs encoding, a sequence of bytes is written to
      the outputstream rather than just the low 8 bits. The use of the writer is also unnecessary. See suggested fix for alternate code without the writer.

      Will be filing the related bug in URLDecoder.decode() for related problem.

      Seen in 1.2.2 and in 1.3.

            michaelm Michael McMahon
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: