HTTPCLIENT-1695: RFC 6265 compliant cookie spec to ignore cookies with empty name / missing value

git-svn-id: https://svn.apache.org/repos/asf/httpcomponents/httpclient/branches/4.5.x@1714365 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Oleg Kalnichevski 2015-11-14 20:45:32 +00:00
parent 549c26f958
commit cd8c72626f
2 changed files with 8 additions and 6 deletions

View File

@ -130,10 +130,10 @@ public class RFC6265CookieSpec implements CookieSpec {
}
final String name = tokenParser.parseToken(buffer, cursor, TOKEN_DELIMS);
if (name.length() == 0) {
throw new MalformedCookieException("Cookie name is invalid: '" + header.toString() + "'");
return Collections.emptyList();
}
if (cursor.atEnd()) {
throw new MalformedCookieException("Cookie value is invalid: '" + header.toString() + "'");
return Collections.emptyList();
}
final int valueDelim = buffer.charAt(cursor.getPos());
cursor.updatePos(cursor.getPos() + 1);

View File

@ -98,22 +98,24 @@ public class TestRFC6265CookieSpec {
cookiespec.parse(header, origin);
}
@Test(expected = MalformedCookieException.class)
@Test
public void testParseCookieMissingName() throws Exception {
final RFC6265CookieSpec cookiespec = new RFC6265CookieSpec();
final Header header = new BasicHeader("Set-Cookie", "=blah ; this = stuff;");
final CookieOrigin origin = new CookieOrigin("host", 80, "/path/", true);
cookiespec.parse(header, origin);
final List<Cookie> cookies = cookiespec.parse(header, origin);
Assert.assertEquals(0, cookies.size());
}
@Test(expected = MalformedCookieException.class)
@Test
public void testParseCookieMissingValue1() throws Exception {
final RFC6265CookieSpec cookiespec = new RFC6265CookieSpec();
final Header header = new BasicHeader("Set-Cookie", "blah");
final CookieOrigin origin = new CookieOrigin("host", 80, "/path/", true);
cookiespec.parse(header, origin);
final List<Cookie> cookies = cookiespec.parse(header, origin);
Assert.assertEquals(0, cookies.size());
}
@Test(expected = MalformedCookieException.class)