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.12 diff -u -r1.12 CookieSpecBase.java --- java/org/apache/commons/httpclient/cookie/CookieSpecBase.java 18 Feb 2003 15:54:30 -0000 1.12 +++ java/org/apache/commons/httpclient/cookie/CookieSpecBase.java 7 Mar 2003 13:28:22 -0000 @@ -646,7 +646,12 @@ throw new IllegalArgumentException("Cookie may not be null"); } StringBuffer buf = new StringBuffer(); - buf.append(cookie.getName()).append("=").append(cookie.getValue()); + buf.append(cookie.getName()); + buf.append("="); + String s = cookie.getValue(); + if (s != null) { + buf.append(s); + }; return buf.toString(); } Index: java/org/apache/commons/httpclient/cookie/RFC2109Spec.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/cookie/RFC2109Spec.java,v retrieving revision 1.12 diff -u -r1.12 RFC2109Spec.java --- java/org/apache/commons/httpclient/cookie/RFC2109Spec.java 31 Jan 2003 00:33:36 -0000 1.12 +++ java/org/apache/commons/httpclient/cookie/RFC2109Spec.java 7 Mar 2003 13:28:22 -0000 @@ -203,9 +203,18 @@ final StringBuffer buffer = new StringBuffer(); if (version < 1) { - buffer.append(name).append("=").append(value); + buffer.append(name); + buffer.append("="); + if (value != null) { + buffer.append(value); + } } else { - buffer.append(name).append("=\"").append(value).append("\""); + buffer.append(name); + buffer.append("=\""); + if (value != null) { + buffer.append(value); + } + buffer.append("\""); } return buffer.toString(); } 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.20 diff -u -r1.20 TestCookie.java --- test/org/apache/commons/httpclient/TestCookie.java 28 Jan 2003 22:09:51 -0000 1.20 +++ test/org/apache/commons/httpclient/TestCookie.java 7 Mar 2003 13:28:21 -0000 @@ -744,7 +744,7 @@ */ public void testDefaultConsttuctor() { Cookie dummy = new Cookie(); - assertEquals( "noname=null", dummy.toExternalForm() ); + assertEquals( "noname=", dummy.toExternalForm() ); } /** @@ -752,9 +752,9 @@ */ public void testDomainCaseInsensitivity() { Header setCookie = new Header( - "Set-Cookie", "name=value; path=/; domain=.sybase.com"); + "Set-Cookie", "name=value; path=/; domain=.whatever.com"); try { - Cookie[] parsed = cookieParse("www.Sybase.com", "/", false, setCookie ); + Cookie[] parsed = cookieParse("www.WhatEver.com", "/", false, setCookie ); } catch(HttpException e) { e.printStackTrace(); @@ -762,6 +762,7 @@ } } + /** * Tests if cookie constructor rejects cookie name containing blanks. */ @@ -961,6 +962,26 @@ } + /** + * Tests if null cookie values are handled correctly. + */ + public void testNullCookieValueFormatting() { + Cookie cookie = new Cookie(".whatever.com", "name", null, "/", null, false); + cookie.setDomainAttributeSpecified(true); + cookie.setPathAttributeSpecified(true); + + CookieSpec parser = null; + String s = null; + + parser = CookiePolicy.getSpecByPolicy(CookiePolicy.COMPATIBILITY); + s = parser.formatCookie(cookie); + assertEquals("name=", s); + + parser = CookiePolicy.getSpecByPolicy(CookiePolicy.RFC2109); + s = parser.formatCookie(cookie); + assertEquals("$Version=0; name=; $Domain=.whatever.com; $Path=/", s); + } + }