Index: src/test/org/apache/commons/httpclient/cookie/TestCookieRFC2109Spec.java =================================================================== --- src/test/org/apache/commons/httpclient/cookie/TestCookieRFC2109Spec.java (revision 148920) +++ src/test/org/apache/commons/httpclient/cookie/TestCookieRFC2109Spec.java (working copy) @@ -1,7 +1,7 @@ /* * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//httpclient/src/test/org/apache/commons/httpclient/cookie/TestCookieRFC2109Spec.java,v 1.3 2004/06/05 16:49:20 olegk Exp $ * $Revision: 1.3 $ - * $Date: 2004/06/05 16:49:20 $ + * $Date$ * ==================================================================== * * Copyright 1999-2004 The Apache Software Foundation @@ -222,6 +222,15 @@ } } + public void testSecondDomainLevelCookieMatch() throws Exception { + Cookie cookie = new Cookie(".sourceforge.net", "name", null, "/", null, false); + cookie.setDomainAttributeSpecified(true); + cookie.setPathAttributeSpecified(true); + + CookieSpec cookiespec = new RFC2109Spec(); + assertFalse(cookiespec.match("sourceforge.net", 80, "/", false, cookie)); + } + public void testParseWithWrongPath() throws Exception { Header header = new Header("Set-Cookie", "cookie-name=cookie-value; domain=127.0.0.1; path=/not/just/root"); Index: src/test/org/apache/commons/httpclient/cookie/TestCookieCompatibilitySpec.java =================================================================== --- src/test/org/apache/commons/httpclient/cookie/TestCookieCompatibilitySpec.java (revision 148920) +++ src/test/org/apache/commons/httpclient/cookie/TestCookieCompatibilitySpec.java (working copy) @@ -1,7 +1,7 @@ /* * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//httpclient/src/test/org/apache/commons/httpclient/cookie/TestCookieCompatibilitySpec.java,v 1.7 2004/09/14 20:11:32 olegk Exp $ * $Revision: 1.7 $ - * $Date: 2004/09/14 20:11:32 $ + * $Date$ * ==================================================================== * * Copyright 1999-2004 The Apache Software Foundation @@ -792,6 +792,15 @@ cookiespec.validate("sourceforge.net", 80, "/", false, cookie); } + public void testSecondDomainLevelCookieMatch() throws Exception { + Cookie cookie = new Cookie(".sourceforge.net", "name", null, "/", null, false); + cookie.setDomainAttributeSpecified(true); + cookie.setPathAttributeSpecified(true); + + CookieSpec cookiespec = new CookieSpecBase(); + assertTrue(cookiespec.match("sourceforge.net", 80, "/", false, cookie)); + } + public void testMatchNullHost() throws Exception { CookieSpec cookiespec = new CookieSpecBase(); Cookie cookie = new Cookie(); Index: src/java/org/apache/commons/httpclient/cookie/CookieSpecBase.java =================================================================== --- src/java/org/apache/commons/httpclient/cookie/CookieSpecBase.java (revision 148920) +++ src/java/org/apache/commons/httpclient/cookie/CookieSpecBase.java (working copy) @@ -1,7 +1,7 @@ /* * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//httpclient/src/java/org/apache/commons/httpclient/cookie/CookieSpecBase.java,v 1.28 2004/11/06 19:15:42 mbecke Exp $ * $Revision: 1.28 $ - * $Date: 2004/11/06 19:15:42 $ + * $Date$ * * ==================================================================== * @@ -503,7 +503,8 @@ * @return true if the specified host matches the given domain. */ public boolean domainMatch(final String host, final String domain) { - return host.endsWith(domain); + return host.endsWith(domain) + || (domain.startsWith(".") && host.endsWith(domain.substring(1))); } /** Index: src/java/org/apache/commons/httpclient/cookie/NetscapeDraftSpec.java =================================================================== --- src/java/org/apache/commons/httpclient/cookie/NetscapeDraftSpec.java (revision 148920) +++ src/java/org/apache/commons/httpclient/cookie/NetscapeDraftSpec.java (working copy) @@ -1,7 +1,7 @@ /* * $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//httpclient/src/java/org/apache/commons/httpclient/cookie/NetscapeDraftSpec.java,v 1.11 2004/05/13 04:02:00 mbecke Exp $ * $Revision: 1.11 $ - * $Date: 2004/05/13 04:02:00 $ + * $Date$ * * ==================================================================== * @@ -197,6 +197,16 @@ } /** + * Performs domain-match as described in the Netscape draft. + * @param host The target host. + * @param domain The cookie domain attribute. + * @return true if the specified host matches the given domain. + */ + public boolean domainMatch(final String host, final String domain) { + return host.endsWith(domain); + } + + /** * Performs Netscape draft compliant {@link Cookie} validation * * @param host the host from which the {@link Cookie} was received