You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2012/09/20 21:20:24 UTC
svn commit: r1388169 - in /httpcomponents/httpcore/branches/4.2.x:
RELEASE_NOTES.txt
httpcore/src/main/java/org/apache/http/entity/ContentType.java
httpcore/src/main/java/org/apache/http/util/EntityUtils.java
Author: olegk
Date: Thu Sep 20 19:20:24 2012
New Revision: 1388169
URL: http://svn.apache.org/viewvc?rev=1388169&view=rev
Log:
HTTPCORE-313: ContentType#parse to ignore empty charset attributes; HttpEntityUtils#toString to throw checked I/O exception if it encounters an unsupported charset
Modified:
httpcomponents/httpcore/branches/4.2.x/RELEASE_NOTES.txt
httpcomponents/httpcore/branches/4.2.x/httpcore/src/main/java/org/apache/http/entity/ContentType.java
httpcomponents/httpcore/branches/4.2.x/httpcore/src/main/java/org/apache/http/util/EntityUtils.java
Modified: httpcomponents/httpcore/branches/4.2.x/RELEASE_NOTES.txt
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/4.2.x/RELEASE_NOTES.txt?rev=1388169&r1=1388168&r2=1388169&view=diff
==============================================================================
--- httpcomponents/httpcore/branches/4.2.x/RELEASE_NOTES.txt (original)
+++ httpcomponents/httpcore/branches/4.2.x/RELEASE_NOTES.txt Thu Sep 20 19:20:24 2012
@@ -1,3 +1,10 @@
+Changes since Release 4.2.2
+
+* [HTTPCORE-313] ContentType#parse now ignores empty attributes. HttpEntityUtils#toString now
+ throws checked I/O exception if it encounters an unsupported charset.
+ Contributed by Oleg Kalnichevski <olegk at apache.org>
+
+
Release 4.2.2
-------------------
Modified: httpcomponents/httpcore/branches/4.2.x/httpcore/src/main/java/org/apache/http/entity/ContentType.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/4.2.x/httpcore/src/main/java/org/apache/http/entity/ContentType.java?rev=1388169&r1=1388168&r2=1388169&view=diff
==============================================================================
--- httpcomponents/httpcore/branches/4.2.x/httpcore/src/main/java/org/apache/http/entity/ContentType.java (original)
+++ httpcomponents/httpcore/branches/4.2.x/httpcore/src/main/java/org/apache/http/entity/ContentType.java Thu Sep 20 19:20:24 2012
@@ -177,7 +177,8 @@ public final class ContentType implement
*/
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.length() > 0) ? Charset.forName(charset) : null);
}
private static ContentType create(final HeaderElement helem) {
@@ -245,7 +246,8 @@ public final class ContentType implement
* @throws ParseException if the given text does not represent a valid
* <code>Content-Type</code> value.
*/
- public static ContentType getOrDefault(final HttpEntity entity) throws ParseException {
+ public static ContentType getOrDefault(
+ final HttpEntity entity) throws ParseException, UnsupportedCharsetException {
ContentType contentType = get(entity);
return contentType != null ? contentType : DEFAULT_TEXT;
}
Modified: httpcomponents/httpcore/branches/4.2.x/httpcore/src/main/java/org/apache/http/util/EntityUtils.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/branches/4.2.x/httpcore/src/main/java/org/apache/http/util/EntityUtils.java?rev=1388169&r1=1388168&r2=1388169&view=diff
==============================================================================
--- httpcomponents/httpcore/branches/4.2.x/httpcore/src/main/java/org/apache/http/util/EntityUtils.java (original)
+++ httpcomponents/httpcore/branches/4.2.x/httpcore/src/main/java/org/apache/http/util/EntityUtils.java Thu Sep 20 19:20:24 2012
@@ -31,7 +31,9 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
+import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
+import java.nio.charset.UnsupportedCharsetException;
import org.apache.http.HeaderElement;
import org.apache.http.HttpEntity;
@@ -209,8 +211,13 @@ public final class EntityUtils {
if (i < 0) {
i = 4096;
}
- ContentType contentType = ContentType.getOrDefault(entity);
- Charset charset = contentType.getCharset();
+ Charset charset = null;
+ try {
+ ContentType contentType = ContentType.getOrDefault(entity);
+ charset = contentType.getCharset();
+ } catch (UnsupportedCharsetException ex) {
+ throw new UnsupportedEncodingException(ex.getMessage());
+ }
if (charset == null) {
charset = defaultCharset;
}