olegk 2003/10/20 15:26:28 Modified: httpclient/src/java/org/apache/commons/httpclient/cookie CookieSpecBase.java httpclient/src/test/org/apache/commons/httpclient TestCookie.java Log: PR# 23866 (Invalid cookie causing IllegalArgumentException) Contributed by Oleg Kalnichevski Reviewed by Michael Becke Revision Changes Path 1.19 +14 -10 jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/cookie/CookieSpecBase.java Index: CookieSpecBase.java =================================================================== RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/cookie/CookieSpecBase.java,v retrieving revision 1.18 retrieving revision 1.19 diff -u -r1.18 -r1.19 --- CookieSpecBase.java 13 Jul 2003 21:29:05 -0000 1.18 +++ CookieSpecBase.java 20 Oct 2003 22:26:28 -0000 1.19 @@ -206,13 +206,17 @@ for (int i = 0; i < headerElements.length; i++) { HeaderElement headerelement = headerElements[i]; - Cookie cookie = new Cookie(host, - headerelement.getName(), - headerelement.getValue(), - defaultPath, - null, - false); - + Cookie cookie = null; + try { + cookie = new Cookie(host, + headerelement.getName(), + headerelement.getValue(), + defaultPath, + null, + false); + } catch (IllegalArgumentException e) { + throw new MalformedCookieException(e.getMessage()); + } // cycle through the parameters NameValuePair[] parameters = headerelement.getParameters(); // could be null. In case only a header element and no parameters. 1.25 +12 -10 jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestCookie.java Index: TestCookie.java =================================================================== RCS file: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestCookie.java,v retrieving revision 1.24 retrieving revision 1.25 diff -u -r1.24 -r1.25 --- TestCookie.java 20 Oct 2003 22:17:12 -0000 1.24 +++ TestCookie.java 20 Oct 2003 22:26:28 -0000 1.25 @@ -787,10 +787,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 } @@ -803,10 +804,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 }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]