Index: java/org/apache/commons/httpclient/Cookie.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/Cookie.java,v retrieving revision 1.38.2.1 diff -u -r1.38.2.1 Cookie.java --- java/org/apache/commons/httpclient/Cookie.java 7 Jul 2003 19:11:00 -0000 1.38.2.1 +++ java/org/apache/commons/httpclient/Cookie.java 16 Oct 2003 14:56:40 -0000 @@ -135,18 +135,6 @@ super(name, value); LOG.trace("enter Cookie(String, String, String, String, Date, boolean)"); - if (name == null) { - throw new IllegalArgumentException("Cookie name may not be null"); - } - if (name.equals("")) { - throw new IllegalArgumentException("Cookie name may not be blank"); - } - if (name.indexOf(' ') != -1) { - throw new IllegalArgumentException("Cookie name may not contain blanks"); - } - if (name.startsWith("$")) { - throw new IllegalArgumentException("Cookie name may not start with $"); - } this.setPath(path); this.setDomain(domain); this.setExpiryDate(expires); Index: java/org/apache/commons/httpclient/cookie/CookieSpecBase.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/cookie/CookieSpecBase.java,v retrieving revision 1.16 diff -u -r1.16 CookieSpecBase.java --- java/org/apache/commons/httpclient/cookie/CookieSpecBase.java 12 Jun 2003 19:12:16 -0000 1.16 +++ java/org/apache/commons/httpclient/cookie/CookieSpecBase.java 16 Oct 2003 14:56:41 -0000 @@ -189,6 +189,19 @@ for (int i = 0; i < headerElements.length; i++) { HeaderElement headerelement = headerElements[i]; + String name = headerelement.getName(); + if (name == null) { + throw new MalformedCookieException("Cookie name may not be null"); + } + if (name.equals("")) { + throw new MalformedCookieException("Cookie name may not be blank"); + } + if (name.indexOf(' ') != -1) { + throw new MalformedCookieException("Cookie name may not contain blanks"); + } + if (name.startsWith("$")) { + throw new MalformedCookieException("Cookie name may not start with $"); + } Cookie cookie = new Cookie(host, headerelement.getName(), headerelement.getValue(), Index: test/org/apache/commons/httpclient/TestCookie.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestCookie.java,v retrieving revision 1.22 diff -u -r1.22 TestCookie.java --- test/org/apache/commons/httpclient/TestCookie.java 12 Jun 2003 19:12:16 -0000 1.22 +++ test/org/apache/commons/httpclient/TestCookie.java 16 Oct 2003 14:56:41 -0000 @@ -786,10 +786,11 @@ public void testInvalidCookieName() { try { - Cookie dummy = new Cookie("localhost", "invalid name", "cooke name may not have blanks"); - fail("IllegalArgumentException must have been thrown"); + CookieSpec parser = new CookieSpecBase(); + parser.parse("localhost", 80, "/", false, "invalid name="); + fail("MalformedCookieException must have been thrown"); } - catch(IllegalArgumentException e) + catch(MalformedCookieException e) { // Expected } @@ -802,10 +803,11 @@ public void testInvalidCookieName2() { try { - Cookie dummy = new Cookie("localhost", "$invalid_name", "cooke name may not start with $"); - fail("IllegalArgumentException must have been thrown"); + CookieSpec parser = new CookieSpecBase(); + parser.parse("localhost", 80, "/", false, "$invalid_name="); + fail("MalformedCookieException must have been thrown"); } - catch(IllegalArgumentException e) + catch(MalformedCookieException e) { // Expected }