You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ol...@apache.org on 2003/03/07 19:23:47 UTC
cvs commit: jakarta-commons/httpclient/src/test/org/apache/commons/httpclient TestCookie.java
olegk 2003/03/07 10:23:47
Modified: httpclient/src/java/org/apache/commons/httpclient/cookie
CookieSpecBase.java RFC2109Spec.java
httpclient/src/test/org/apache/commons/httpclient
TestCookie.java
Log:
Fixes the null-value cookie formatting bug reported by Tom Samplonius <to...@sdf.com>
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=17768
Contributed by Oleg Kalnichevski
Revision Changes Path
1.13 +9 -4 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.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- CookieSpecBase.java 18 Feb 2003 15:54:30 -0000 1.12
+++ CookieSpecBase.java 7 Mar 2003 18:23:45 -0000 1.13
@@ -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();
}
1.13 +14 -5 jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/cookie/RFC2109Spec.java
Index: RFC2109Spec.java
===================================================================
RCS file: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/cookie/RFC2109Spec.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- RFC2109Spec.java 31 Jan 2003 00:33:36 -0000 1.12
+++ RFC2109Spec.java 7 Mar 2003 18:23:46 -0000 1.13
@@ -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();
}
1.21 +28 -7 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.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- TestCookie.java 28 Jan 2003 22:09:51 -0000 1.20
+++ TestCookie.java 7 Mar 2003 18:23:46 -0000 1.21
@@ -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);
+ }
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org