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:
parent
549c26f958
commit
cd8c72626f
|
@ -130,10 +130,10 @@ public class RFC6265CookieSpec implements CookieSpec {
|
||||||
}
|
}
|
||||||
final String name = tokenParser.parseToken(buffer, cursor, TOKEN_DELIMS);
|
final String name = tokenParser.parseToken(buffer, cursor, TOKEN_DELIMS);
|
||||||
if (name.length() == 0) {
|
if (name.length() == 0) {
|
||||||
throw new MalformedCookieException("Cookie name is invalid: '" + header.toString() + "'");
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
if (cursor.atEnd()) {
|
if (cursor.atEnd()) {
|
||||||
throw new MalformedCookieException("Cookie value is invalid: '" + header.toString() + "'");
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
final int valueDelim = buffer.charAt(cursor.getPos());
|
final int valueDelim = buffer.charAt(cursor.getPos());
|
||||||
cursor.updatePos(cursor.getPos() + 1);
|
cursor.updatePos(cursor.getPos() + 1);
|
||||||
|
|
|
@ -98,22 +98,24 @@ public class TestRFC6265CookieSpec {
|
||||||
cookiespec.parse(header, origin);
|
cookiespec.parse(header, origin);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = MalformedCookieException.class)
|
@Test
|
||||||
public void testParseCookieMissingName() throws Exception {
|
public void testParseCookieMissingName() throws Exception {
|
||||||
final RFC6265CookieSpec cookiespec = new RFC6265CookieSpec();
|
final RFC6265CookieSpec cookiespec = new RFC6265CookieSpec();
|
||||||
|
|
||||||
final Header header = new BasicHeader("Set-Cookie", "=blah ; this = stuff;");
|
final Header header = new BasicHeader("Set-Cookie", "=blah ; this = stuff;");
|
||||||
final CookieOrigin origin = new CookieOrigin("host", 80, "/path/", true);
|
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 {
|
public void testParseCookieMissingValue1() throws Exception {
|
||||||
final RFC6265CookieSpec cookiespec = new RFC6265CookieSpec();
|
final RFC6265CookieSpec cookiespec = new RFC6265CookieSpec();
|
||||||
|
|
||||||
final Header header = new BasicHeader("Set-Cookie", "blah");
|
final Header header = new BasicHeader("Set-Cookie", "blah");
|
||||||
final CookieOrigin origin = new CookieOrigin("host", 80, "/path/", true);
|
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(expected = MalformedCookieException.class)
|
||||||
|
|
Loading…
Reference in New Issue