You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by "Guillaume Castagnino (JIRA)" <ji...@apache.org> on 2012/09/19 15:25:07 UTC
[jira] [Created] (HTTPCORE-313) ContentType.create(final String
mimeType, final String charset) uncaught exception when charset == ""
Guillaume Castagnino created HTTPCORE-313:
---------------------------------------------
Summary: ContentType.create(final String mimeType, final String charset) uncaught exception when charset == ""
Key: HTTPCORE-313
URL: https://issues.apache.org/jira/browse/HTTPCORE-313
Project: HttpComponents HttpCore
Issue Type: Bug
Components: HttpCore
Affects Versions: 4.2.1
Environment: Ubuntu 12.04 LTS with openjdk-7
Reporter: Guillaume Castagnino
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 ?
--
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
[jira] [Commented] (HTTPCORE-313) ContentType.create(final String
mimeType, final String charset) uncaught exception when charset == ""
Posted by "Gary D. Gregory (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/HTTPCORE-313?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13458989#comment-13458989 ]
Gary D. Gregory commented on HTTPCORE-313:
------------------------------------------
It seems sensible. What about a string full of white space (space, tab and so on)?
> ContentType.create(final String mimeType, final String charset) uncaught exception when charset == ""
> -----------------------------------------------------------------------------------------------------
>
> Key: HTTPCORE-313
> URL: https://issues.apache.org/jira/browse/HTTPCORE-313
> Project: HttpComponents HttpCore
> Issue Type: Bug
> Components: HttpCore
> Affects Versions: 4.2.1
> Environment: Ubuntu 12.04 LTS with openjdk-7
> Reporter: Guillaume Castagnino
>
> 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 ?
--
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
[jira] [Resolved] (HTTPCORE-313) ContentType.create(final String
mimeType, final String charset) uncaught exception when charset == ""
Posted by "Oleg Kalnichevski (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/HTTPCORE-313?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Oleg Kalnichevski resolved HTTPCORE-313.
----------------------------------------
Resolution: Fixed
Fix Version/s: 4.3-alpha1
4.2.3
I think the real problem is that EntityUtils#toString method does not rethrow IllegalCharsetNameException as a checked I/O exception. I fixed the problem in the trunk and the 4.2.x branch. I also made ContentType#create ignore empty charsets in the 4.2.x and ignore blank (empty or containing white spaces only) charsets in the trunk.
Please review / test.
Oleg
> ContentType.create(final String mimeType, final String charset) uncaught exception when charset == ""
> -----------------------------------------------------------------------------------------------------
>
> Key: HTTPCORE-313
> URL: https://issues.apache.org/jira/browse/HTTPCORE-313
> Project: HttpComponents HttpCore
> Issue Type: Bug
> Components: HttpCore
> Affects Versions: 4.2.1
> Environment: Ubuntu 12.04 LTS with openjdk-7
> Reporter: Guillaume Castagnino
> Fix For: 4.2.3, 4.3-alpha1
>
>
> 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 ?
--
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
[jira] [Commented] (HTTPCORE-313) ContentType.create(final String
mimeType, final String charset) uncaught exception when charset == ""
Posted by "Guillaume Castagnino (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/HTTPCORE-313?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13459400#comment-13459400 ]
Guillaume Castagnino commented on HTTPCORE-313:
-----------------------------------------------
Indeed, same as empty string. But spaces in charset are non-significant. So I would suggest to trim the string. For example something like this:
--- ContentType.java.orig 2012-09-20 08:55:57.679827312 +0200
+++ ContentType.java 2012-09-20 08:59:51.103819363 +0200
@@ -174,7 +174,7 @@
*/
public static ContentType create(
final String mimeType, final String charset) throws UnsupportedCharsetException {
- return create(mimeType, charset != null ? Charset.forName(charset) : null);
+ return create(mimeType, charset != null && !charset.trim().isEmpty() ? Charset.forName(charset.trim()) : null);
}
private static ContentType create(final HeaderElement helem) {
> ContentType.create(final String mimeType, final String charset) uncaught exception when charset == ""
> -----------------------------------------------------------------------------------------------------
>
> Key: HTTPCORE-313
> URL: https://issues.apache.org/jira/browse/HTTPCORE-313
> Project: HttpComponents HttpCore
> Issue Type: Bug
> Components: HttpCore
> Affects Versions: 4.2.1
> Environment: Ubuntu 12.04 LTS with openjdk-7
> Reporter: Guillaume Castagnino
>
> 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 ?
--
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