6790677: java.net.HttpCookie.parse(String) should ignore unrecognized attributes, RFC2965
authorjccollet
Tue, 27 Jan 2009 11:36:28 +0100
changeset 1932 d3506bce7d27
parent 1826 39d505a353e8
child 1933 1210d93b6ee7
6790677: java.net.HttpCookie.parse(String) should ignore unrecognized attributes, RFC2965 Summary: Changed code not to throw an exception on unknown attributes Reviewed-by: chegar
jdk/src/share/classes/java/net/HttpCookie.java
jdk/test/java/net/CookieHandler/TestHttpCookie.java
--- a/jdk/src/share/classes/java/net/HttpCookie.java	Mon Jan 26 19:49:26 2009 -0800
+++ b/jdk/src/share/classes/java/net/HttpCookie.java	Tue Jan 27 11:36:28 2009 +0100
@@ -1058,8 +1058,7 @@
         if (assignor != null) {
             assignor.assign(cookie, attrName, attrValue);
         } else {
-            // must be an error
-            throw new IllegalArgumentException("Illegal cookie attribute");
+            // Ignore the attribute as per RFC 2965
         }
     }
 
--- a/jdk/test/java/net/CookieHandler/TestHttpCookie.java	Mon Jan 26 19:49:26 2009 -0800
+++ b/jdk/test/java/net/CookieHandler/TestHttpCookie.java	Tue Jan 27 11:36:28 2009 +0100
@@ -24,7 +24,7 @@
 /**
  * @test
  * @summary Unit test for java.net.HttpCookie
- * @bug 6244040 6277796 6277801 6277808 6294071 6692802
+ * @bug 6244040 6277796 6277801 6277808 6294071 6692802 6790677
  * @author Edward Wang
  */
 
@@ -278,10 +278,6 @@
         .c("this is a coyote").cu("http://www.coyote.org").dsc(true)
         .d(".coyote.org").a(3600).port("80");
 
-        // illegal characters in set-cookie header
-        test("Set-Cookie2:Customer=;Version#=\"1\";Path=&\"/acme\"")
-        .nil();
-
         // empty set-cookie string
         test("").nil();
 
@@ -311,6 +307,9 @@
         test("Set-Cookie2:C1=\"V1\";Domain=\".sun1.com\";path=\"/www1\";Max-Age=\"100\",C2=\"V2\";Domain=\".sun2.com\";path=\"/www2\";Max-Age=\"200\"")
         .n(0, "C1").v(0, "V1").p(0, "/www1").a(0, 100).d(0, ".sun1.com")
         .n(1, "C2").v(1, "V2").p(1, "/www2").a(1, 200).d(1, ".sun2.com");
+
+        // Bug 6790677: Should ignore bogus attributes
+        test("Set-Cookie2:C1=\"V1\";foobar").n(0, "C1").v(0, "V1");
     }
 
     static void netscape() {