You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by vi...@apache.org on 2013/08/20 18:38:49 UTC

svn commit: r1515862 - in /tomcat/tc7.0.x/trunk: ./ java/org/apache/tomcat/util/http/parser/HttpParser.java test/org/apache/tomcat/util/http/parser/TestMediaType.java webapps/docs/changelog.xml

Author: violetagg
Date: Tue Aug 20 16:38:49 2013
New Revision: 1515862

URL: http://svn.apache.org/r1515862
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=55454
Merged revision 1515841 from tomcat/trunk:
Fixed NPE thrown when parsing an invalid content type.

Modified:
    tomcat/tc7.0.x/trunk/   (props changed)
    tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/parser/HttpParser.java
    tomcat/tc7.0.x/trunk/test/org/apache/tomcat/util/http/parser/TestMediaType.java
    tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml

Propchange: tomcat/tc7.0.x/trunk/
------------------------------------------------------------------------------
  Merged /tomcat/trunk:r1515841

Modified: tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/parser/HttpParser.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/parser/HttpParser.java?rev=1515862&r1=1515861&r2=1515862&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/parser/HttpParser.java (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/parser/HttpParser.java Tue Aug 20 16:38:49 2013
@@ -210,11 +210,13 @@ public class HttpParser {
         while (lookForSemiColon == SkipConstantResult.FOUND) {
             String attribute = readToken(input);
 
+            String value = "";
             if (skipConstant(input, "=") == SkipConstantResult.FOUND) {
-                String value = readTokenOrQuotedString(input, true);
+                value = readTokenOrQuotedString(input, true);
+            }
+
+            if (attribute != null) {
                 parameters.put(attribute.toLowerCase(Locale.ENGLISH), value);
-            } else {
-                parameters.put(attribute.toLowerCase(Locale.ENGLISH), "");
             }
 
             lookForSemiColon = skipConstant(input, ";");

Modified: tomcat/tc7.0.x/trunk/test/org/apache/tomcat/util/http/parser/TestMediaType.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/test/org/apache/tomcat/util/http/parser/TestMediaType.java?rev=1515862&r1=1515861&r2=1515862&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/test/org/apache/tomcat/util/http/parser/TestMediaType.java (original)
+++ tomcat/tc7.0.x/trunk/test/org/apache/tomcat/util/http/parser/TestMediaType.java Tue Aug 20 16:38:49 2013
@@ -212,6 +212,25 @@ public class TestMediaType {
     }
 
 
+    @Test
+    public void testBug55454() throws IOException {
+        String input = "text/html;;charset=UTF-8";
+
+        StringReader sr = new StringReader(input);
+        MediaType m = HttpParser.parseMediaType(sr);
+
+        assertEquals("text", m.getType());
+        assertEquals("html", m.getSubtype());
+
+        assertTrue(m.getParameterCount() == 1);
+
+        assertEquals("UTF-8", m.getParameterValue("charset"));
+        assertEquals("UTF-8", m.getCharset());
+
+        assertEquals("text/html; charset=UTF-8", m.toString());
+    }
+
+
     private void doTest(Parameter... parameters) throws IOException {
         for (String lws : LWS_VALUES) {
             doTest(lws, parameters);

Modified: tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml?rev=1515862&r1=1515861&r2=1515862&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml Tue Aug 20 16:38:49 2013
@@ -120,6 +120,10 @@
         <bug>55404</bug>: Log warnings about using security roles in web.xml
         without defining them as warnings. (markt)
       </fix>
+      <fix>
+        <bug>55454</bug>: Avoid NPE when parsing an incorrect content type.
+        (violetagg)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Coyote">



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