diff --git a/src/java/org/apache/http/cookie/impl/BasicPathHandler.java b/src/java/org/apache/http/cookie/impl/BasicPathHandler.java index 9bb1e8f4e..32dcda80e 100644 --- a/src/java/org/apache/http/cookie/impl/BasicPathHandler.java +++ b/src/java/org/apache/http/cookie/impl/BasicPathHandler.java @@ -68,9 +68,6 @@ public class BasicPathHandler implements CookieAttributeHandler { throw new IllegalArgumentException("Cookie origin may not be null"); } String targetpath = origin.getPath(); - if (targetpath == null) { - targetpath = "/"; - } String topmostPath = cookie.getPath(); if (topmostPath == null) { topmostPath = "/"; diff --git a/src/java/org/apache/http/cookie/impl/BrowserCompatSpec.java b/src/java/org/apache/http/cookie/impl/BrowserCompatSpec.java index 3dc44846d..5395c976e 100644 --- a/src/java/org/apache/http/cookie/impl/BrowserCompatSpec.java +++ b/src/java/org/apache/http/cookie/impl/BrowserCompatSpec.java @@ -83,7 +83,7 @@ public class BrowserCompatSpec extends CookieSpecBase { if (header == null) { throw new IllegalArgumentException("Header may not be null"); } - if (header == null) { + if (origin == null) { throw new IllegalArgumentException("Cookie origin may not be null"); } String headervalue = header.getValue(); diff --git a/src/java/org/apache/http/cookie/impl/CookieSpecBase.java b/src/java/org/apache/http/cookie/impl/CookieSpecBase.java index 18d463baa..b1fbcecd8 100644 --- a/src/java/org/apache/http/cookie/impl/CookieSpecBase.java +++ b/src/java/org/apache/http/cookie/impl/CookieSpecBase.java @@ -103,9 +103,6 @@ public abstract class CookieSpecBase extends AbstractCookieSpec { if (origin == null) { throw new IllegalArgumentException("Cookie origin may not be null"); } - if (cookie.getName() == null || cookie.getName().trim().equals("")) { - throw new MalformedCookieException("Cookie name may not be blank"); - } for (Iterator i = getAttribHandlerIterator(); i.hasNext();) { CookieAttributeHandler handler = (CookieAttributeHandler) i.next(); handler.validate(cookie, origin); diff --git a/src/test/org/apache/http/cookie/impl/TestBrowserCompatSpec.java b/src/test/org/apache/http/cookie/impl/TestBrowserCompatSpec.java index 66a1bd3fe..9cb7ff57f 100644 --- a/src/test/org/apache/http/cookie/impl/TestBrowserCompatSpec.java +++ b/src/test/org/apache/http/cookie/impl/TestBrowserCompatSpec.java @@ -553,6 +553,23 @@ public class TestBrowserCompatSpec extends TestCase { assertEquals(1, parsed.length); } + /** + * Tests if cookie constructor rejects cookie name containing blanks. + */ + public void testCookieNameBlank() throws Exception { + Header header = new Header("Set-Cookie", "=stuff"); + CookieSpec cookiespec = new BrowserCompatSpec(); + CookieOrigin origin = new CookieOrigin("127.0.0.1", 80, "/", false); + try { + Cookie[] parsed = cookiespec.parse(header, origin); + for (int i = 0; i < parsed.length; i++) { + cookiespec.validate(parsed[i], origin); + } + fail("MalformedCookieException should have been thrown"); + } catch (MalformedCookieException expected) { + } + } + /** * Tests if cookie constructor rejects cookie name starting with $. */ @@ -885,5 +902,56 @@ public class TestBrowserCompatSpec extends TestCase { new MalformedCookieException("whatever", null); } + public void testInvalidInput() throws Exception { + CookieSpec cookiespec = new BrowserCompatSpec(); + try { + cookiespec.parse(null, null); + fail("IllegalArgumentException must have been thrown"); + } catch (IllegalArgumentException ex) { + // expected + } + try { + cookiespec.parse(new Header("Set-Cookie", "name=value"), null); + fail("IllegalArgumentException must have been thrown"); + } catch (IllegalArgumentException ex) { + // expected + } + try { + cookiespec.validate(null, null); + fail("IllegalArgumentException must have been thrown"); + } catch (IllegalArgumentException ex) { + // expected + } + try { + cookiespec.validate(new Cookie("name", null), null); + fail("IllegalArgumentException must have been thrown"); + } catch (IllegalArgumentException ex) { + // expected + } + try { + cookiespec.match(null, null); + fail("IllegalArgumentException must have been thrown"); + } catch (IllegalArgumentException ex) { + // expected + } + try { + cookiespec.match(new Cookie("name", null), null); + fail("IllegalArgumentException must have been thrown"); + } catch (IllegalArgumentException ex) { + // expected + } + try { + cookiespec.formatCookies(null); + fail("IllegalArgumentException must have been thrown"); + } catch (IllegalArgumentException ex) { + // expected + } + try { + cookiespec.formatCookies(new Cookie[] {}); + fail("IllegalArgumentException must have been thrown"); + } catch (IllegalArgumentException ex) { + // expected + } + } + } -