From cd8c72626ff84964b21745b1241b87bcb1393d76 Mon Sep 17 00:00:00 2001 From: Oleg Kalnichevski Date: Sat, 14 Nov 2015 20:45:32 +0000 Subject: [PATCH] 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 --- .../org/apache/http/impl/cookie/RFC6265CookieSpec.java | 4 ++-- .../apache/http/impl/cookie/TestRFC6265CookieSpec.java | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/httpclient/src/main/java/org/apache/http/impl/cookie/RFC6265CookieSpec.java b/httpclient/src/main/java/org/apache/http/impl/cookie/RFC6265CookieSpec.java index 3e8e63c00..c9f9b99d3 100644 --- a/httpclient/src/main/java/org/apache/http/impl/cookie/RFC6265CookieSpec.java +++ b/httpclient/src/main/java/org/apache/http/impl/cookie/RFC6265CookieSpec.java @@ -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); diff --git a/httpclient/src/test/java/org/apache/http/impl/cookie/TestRFC6265CookieSpec.java b/httpclient/src/test/java/org/apache/http/impl/cookie/TestRFC6265CookieSpec.java index 82e97a467..fc6adf167 100644 --- a/httpclient/src/test/java/org/apache/http/impl/cookie/TestRFC6265CookieSpec.java +++ b/httpclient/src/test/java/org/apache/http/impl/cookie/TestRFC6265CookieSpec.java @@ -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 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 cookies = cookiespec.parse(header, origin); + Assert.assertEquals(0, cookies.size()); } @Test(expected = MalformedCookieException.class)