hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1482742 - in /httpcomponents/httpcore/trunk/httpcore/src: main/java/org/apache/http/entity/ContentType.java test/java/org/apache/http/entity/TestContentType.java
Date Wed, 15 May 2013 10:01:48 GMT
Author: olegk
Date: Wed May 15 10:01:47 2013
New Revision: 1482742

URL: http://svn.apache.org/r1482742
Log:
HTTPCORE-339: tolerate empty charset attribute when parsing content-type values

Modified:
    httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/ContentType.java
    httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/entity/TestContentType.java

Modified: httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/ContentType.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/ContentType.java?rev=1482742&r1=1482741&r2=1482742&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/ContentType.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/main/java/org/apache/http/entity/ContentType.java
Wed May 15 10:01:47 2013
@@ -108,7 +108,7 @@ public final class ContentType implement
         this.mimeType = mimeType;
         this.params = params;
         final String s = getParameter("charset");
-        this.charset = s != null ? Charset.forName(s) : null;
+        this.charset = !TextUtils.isBlank(s) ? Charset.forName(s) : null;
     }
 
     public String getMimeType() {

Modified: httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/entity/TestContentType.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/entity/TestContentType.java?rev=1482742&r1=1482741&r2=1482742&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/entity/TestContentType.java
(original)
+++ httpcomponents/httpcore/trunk/httpcore/src/test/java/org/apache/http/entity/TestContentType.java
Wed May 15 10:01:47 2013
@@ -131,6 +131,13 @@ public class TestContentType {
     }
 
     @Test
+    public void testParseEmptyCharset() throws Exception {
+        final ContentType contentType = ContentType.parse("text/plain; charset=\" \"");
+        Assert.assertEquals("text/plain", contentType.getMimeType());
+        Assert.assertEquals(null, contentType.getCharset());
+    }
+
+    @Test
     public void testParseInvalidInput() throws Exception {
         try {
             ContentType.parse(null);



Mime
View raw message