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 2009/10/06 15:03:40 UTC

svn commit: r822258 - in /httpcomponents/httpclient/trunk/httpclient/src: main/java/org/apache/http/client/utils/URLEncodedUtils.java test/java/org/apache/http/client/utils/TestURLEncodedUtils.java

Author: olegk
Date: Tue Oct  6 13:03:39 2009
New Revision: 822258

URL: http://svn.apache.org/viewvc?rev=822258&view=rev
Log:
HTTPCLIENT-880: Check for correct content-type in URLEncodedUtils not working for encoding-suffixes

Modified:
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/utils/URLEncodedUtils.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/utils/TestURLEncodedUtils.java

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/utils/URLEncodedUtils.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/utils/URLEncodedUtils.java?rev=822258&r1=822257&r2=822258&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/utils/URLEncodedUtils.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/client/utils/URLEncodedUtils.java Tue Oct  6 13:03:39 2009
@@ -40,6 +40,7 @@
 import org.apache.http.annotation.Immutable;
 
 import org.apache.http.Header;
+import org.apache.http.HeaderElement;
 import org.apache.http.HttpEntity;
 import org.apache.http.NameValuePair;
 import org.apache.http.message.BasicNameValuePair;
@@ -113,8 +114,18 @@
      * <code>application/x-www-form-urlencoded</code>.
      */
     public static boolean isEncoded (final HttpEntity entity) {
-        final Header contentType = entity.getContentType();
-        return (contentType != null && contentType.getValue().equalsIgnoreCase(CONTENT_TYPE));
+        Header h = entity.getContentType();
+        if (h != null) {
+            HeaderElement[] elems = h.getElements();
+            if (elems.length > 0) {
+                String contentType = elems[0].getName();
+                return contentType.equalsIgnoreCase(CONTENT_TYPE);
+            } else {
+                return false;
+            }
+        } else {
+            return false;
+        }
     }
 
     /**

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/utils/TestURLEncodedUtils.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/utils/TestURLEncodedUtils.java?rev=822258&r1=822257&r2=822258&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/utils/TestURLEncodedUtils.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/client/utils/TestURLEncodedUtils.java Tue Oct  6 13:03:39 2009
@@ -118,6 +118,9 @@
         entity.setContentType(URLEncodedUtils.CONTENT_TYPE);
         assertTrue(URLEncodedUtils.isEncoded(entity));
 
+        entity.setContentType(URLEncodedUtils.CONTENT_TYPE + "; charset=US-ASCII");
+        assertTrue(URLEncodedUtils.isEncoded(entity));
+
         entity.setContentType("text/test");
         assertFalse(URLEncodedUtils.isEncoded(entity));
     }