* Improved CookieDecoder to be more tolerant

* Added a test case for comma delimited cookies
This commit is contained in:
Trustin Lee 2009-03-13 16:33:49 +00:00
parent 611364e47c
commit 9e0e310ffe
2 changed files with 36 additions and 1 deletions

View File

@ -58,8 +58,8 @@ public class CookieDecoder {
Set<Cookie> cookies = new TreeSet<Cookie>();
String[] split = header.split(SEMICOLON);
int version = 0;
boolean versionAtTheBeginning = false;
for (int i = 0; i < split.length; i++) {
boolean versionAtTheBeginning = false;
DefaultCookie theCookie;
String s = split[i];
String[] cookie = s.split(EQUALS, 2);

View File

@ -27,6 +27,7 @@ import java.util.Date;
import java.util.Iterator;
import java.util.Set;
import org.junit.Ignore;
import org.junit.Test;
/**
@ -220,6 +221,40 @@ public class CookieDecoderTest {
assertNull(c.getDomain());
assertTrue(c.getPorts().isEmpty());
assertEquals(-1, c.getMaxAge());
}
@Test
@Ignore
public void testDecodingCommaSeparatedClientSideCookies() {
// FIXME Fix CookieDecoder to pass this test.
String source =
"$Version=\"1\"; session_id=\"1234\", " +
"$Version=\"1\"; session_id=\"1111\"; $Domain=\".cracker.edu\"";
Set<Cookie> cookies = new CookieDecoder().decode(source);
Iterator<Cookie> it = cookies.iterator();
Cookie c;
c = it.next();
assertEquals(1, c.getVersion());
assertEquals("session_id", c.getName());
assertEquals("1234", c.getValue());
assertNull(c.getPath());
assertNull(c.getComment());
assertNull(c.getCommentUrl());
assertNull(c.getDomain());
assertTrue(c.getPorts().isEmpty());
assertEquals(-1, c.getMaxAge());
c = it.next();
assertEquals(1, c.getVersion());
assertEquals("session_id", c.getName());
assertEquals("1111", c.getValue());
assertEquals(".cracker.edu", c.getDomain());
assertNull(c.getPath());
assertNull(c.getComment());
assertNull(c.getCommentUrl());
assertTrue(c.getPorts().isEmpty());
assertEquals(-1, c.getMaxAge());
}
}