Partial fix for https://issues.apache.org/bugzilla/show_bug.cgi?id=49000
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Tue, 4 Jan 2011 18:28:23 +0000 (18:28 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Tue, 4 Jan 2011 18:28:23 +0000 (18:28 +0000)
Consistently handle name only cookies (which are not spec complaint)

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1055132 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/tomcat/util/http/Cookies.java
test/org/apache/tomcat/util/http/TestCookies.java

index 01d5bae..39e8eda 100644 (file)
@@ -283,7 +283,7 @@ public final class Cookies { // extends MultiMap {
             // cookie at the end of the cookie header, so if we
             // are past the end of the header, but we have a name
             // skip to the name-only part.
-            if (pos < end && bytes[pos] == '=') {                
+            if (pos < (end - 1) && bytes[pos] == '=') {                
 
                 // Skip whitespace
                 do {
index f156bdd..cd7b5c5 100644 (file)
 
 package org.apache.tomcat.util.http; 
 
-import junit.framework.Test;
 import junit.framework.TestCase;
-import junit.framework.TestSuite;
-import junit.textui.TestRunner;
-
 
 public class TestCookies extends TestCase {
-    public static void main( String args[] ) {
-       TestRunner.run(suite());
-    }
-    public static Test suite() {
-       TestSuite suite = new TestSuite();
-       suite.addTest(new TestSuite(TestCookies.class));
-       return suite;
-    }
-/*
-       int i = 10000000;
-          // These tests are not really representative 
-         while (i-- > 0) { 
-             test("session=1234567890;name=\"John Q. Public\";");
-        }
-//        runtests();
-    } 
- */
-    
+
     public void testCookies() throws Exception {
         test("foo=bar; a=b", "foo", "bar", "a", "b");
         test("foo=bar;a=b", "foo", "bar", "a", "b");
@@ -120,6 +99,20 @@ public class TestCookies extends TestCase {
         test("$Version=0;foo=bar", 0);
     }
 
+
+    public void testNameOnlyCookies() throws Exception {
+        // Bug 49000
+        /*
+        test("fred=1; jim=2; bob", "fred", "1", "jim", "2", "bob", "");
+        test("fred=1; jim=2; bob; george=3", "fred", "1", "jim", "2", "bob", "",
+                "george", "3");
+        test("fred=1; jim=2; bob=; george=3", "fred", "1", "jim", "2",
+                "bob", "", "george", "3");
+        */                    
+        test("fred=1; jim=2; bob=", "fred", "1", "jim", "2", "bob", "");
+    }
+
+
     public static void test( String s, int val ) throws Exception {
         System.out.println("Processing [" + s + "]");
         Cookies cs=new Cookies(null);