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

EntityUtils.toString uses wrong charset if no content-type is provided by server

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Duplicate
    • 4.2.1
    • None
    • HttpCore
    • None

    Description

      The method

      public static String toString( final HttpEntity entity, final String defaultCharset)

      delegates to

      public static String toString( final HttpEntity entity, final Charset defaultCharset) {
      ...
      ContentType contentType = ContentType.getOrDefault(entity);
      Charset charset = contentType.getCharset();
      if (charset == null)

      { charset = defaultCharset; }

      ...
      }

      This method uses a default content type which has a charset set

      public static ContentType getOrDefault(final HttpEntity entity) throws ParseException

      { ContentType contentType = get(entity); return contentType != null ? contentType : DEFAULT_TEXT; }

      public static final ContentType DEFAULT_TEXT = TEXT_PLAIN;
      public static final ContentType TEXT_PLAIN = create( "text/plain", Consts.ISO_8859_1);

      This leads to the situation that the defaultCharset is not used but latin1 encoding from the default content type.

      The default content type should not have an encoding set to prevent this.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              everflux Thomas Kruse
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: