Uploaded image for project: 'HttpComponents HttpCore'
  1. HttpComponents HttpCore
  2. HTTPCORE-313

ContentType.create(final String mimeType, final String charset) uncaught exception when charset == ""

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 4.2.1
    • 4.2.3, 4.3-alpha1
    • HttpCore
    • None
    • Ubuntu 12.04 LTS with openjdk-7

    Description

      I parse a broken HTTP response from a server that replies with a crafted Content-Type header:
      Content-Type: text/html; charset=

      charset is present, but is empty. When using the EntityUtils.toString method, this triggers an uncaught exception in ContentType.create.
      Indeed, it calls this:
      return create(mimeType, charset != null ? Charset.forName(charset) : null);

      charset is checked against the null value. But the empty string is not checked.
      Charset.forName("") throws a "java.nio.charset.IllegalCharsetNameException" exception which is not caught whereas Charset.forName("broken") throws a "java.nio.charset.UnsupportedCharsetException" exception, which is correctly handled.

      So I think that the empty string should be checked and managed like the null, isn't it ?

      Attachments

        Activity

          People

            Unassigned Unassigned
            guilc Guillaume Castagnino
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: