hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Thomas Kruse (JIRA)" <j...@apache.org>
Subject [jira] [Created] (HTTPCORE-329) EntityUtils.toString uses wrong charset if no content-type is provided by server
Date Wed, 16 Jan 2013 14:32:13 GMT
Thomas Kruse created HTTPCORE-329:
-------------------------------------

             Summary: EntityUtils.toString uses wrong charset if no content-type is provided
by server
                 Key: HTTPCORE-329
                 URL: https://issues.apache.org/jira/browse/HTTPCORE-329
             Project: HttpComponents HttpCore
          Issue Type: Bug
          Components: HttpCore
    Affects Versions: 4.2.1
            Reporter: Thomas Kruse


The method
{code}
public static String toString( final HttpEntity entity, final String defaultCharset)
{code}
delegates to
{code}
public static String toString( final HttpEntity entity, final Charset defaultCharset) {
...
   ContentType contentType = ContentType.getOrDefault(entity);
   Charset charset = contentType.getCharset();
   if (charset == null) {
        charset = defaultCharset;
   }
...
}
{code}

This method uses a default content type which has a charset set(!)
{code}
public static ContentType getOrDefault(final HttpEntity entity) throws ParseException {
        ContentType contentType = get(entity);
        return contentType != null ? contentType : DEFAULT_TEXT;
    }
{code}

{code}
public static final ContentType DEFAULT_TEXT = TEXT_PLAIN;

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

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.


--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


Mime
View raw message