Index: java/org/apache/commons/httpclient/cookie/CookieSpec.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/cookie/CookieSpec.java,v retrieving revision 1.8 diff -u -r1.8 CookieSpec.java --- java/org/apache/commons/httpclient/cookie/CookieSpec.java 18 Apr 2004 23:51:37 -0000 1.8 +++ java/org/apache/commons/httpclient/cookie/CookieSpec.java 25 Apr 2004 20:44:44 -0000 @@ -151,6 +151,22 @@ final Cookie cookies[]); /** + * Performs domain-match as defined by the cookie specification. + * @param host The target host. + * @param domain The cookie domain attribute. + * @return true if the specified host matches the given domain. + */ + boolean domainMatch(final String host, final String domain); + + /** + * Performs path-match as defined by the cookie specification. + * @param path The target path. + * @param topmostPath The cookie path attribute. + * @return true if the paths match + */ + boolean pathMatch(final String path, final String topmostPath); + + /** * Create a "Cookie" header value for an array of cookies. * * @param cookie the cookie to be formatted as string Index: java/org/apache/commons/httpclient/cookie/CookieSpecBase.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/cookie/CookieSpecBase.java,v retrieving revision 1.25 diff -u -r1.25 CookieSpecBase.java --- java/org/apache/commons/httpclient/cookie/CookieSpecBase.java 24 Apr 2004 23:51:57 -0000 1.25 +++ java/org/apache/commons/httpclient/cookie/CookieSpecBase.java 25 Apr 2004 20:44:46 -0000 @@ -1,5 +1,5 @@ /* - * $Header: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/cookie/CookieSpecBase.java,v 1.25 2004/04/24 23:51:57 olegk Exp $ + * $Header: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/cookie/CookieSpecBase.java,v 1.25 2004/04/24 23:51:57 olegk Exp $ * $Revision: 1.25 $ * $Date: 2004/04/24 23:51:57 $ * @@ -485,30 +485,23 @@ } /** - * Performs a domain-match as described in RFC2109. - * @param host The host to check. - * @param domain The domain. + * Performs domain-match as implemented in common browsers. + * @param host The target host. + * @param domain The cookie domain attribute. * @return true if the specified host matches the given domain. */ - private static boolean domainMatch(String host, String domain) { - boolean match = host.equals(domain) - || (domain.startsWith(".") && host.endsWith(domain)); - - return match; + public boolean domainMatch(final String host, final String domain) { + return host.endsWith(domain); } /** - * Performs a path-match slightly smarter than a straight-forward startsWith - * check. - * @param path The path to check. - * @param topmostPath The path to check against. + * Performs path-match as implemented in common browsers. + * @param path The target path. + * @param topmostPath The cookie path attribute. * @return true if the paths match */ - private static boolean pathMatch( - final String path, final String topmostPath) { - + public boolean pathMatch(final String path, final String topmostPath) { boolean match = path.startsWith (topmostPath); - // if there is a match and these values are not exactly the same we have // to make sure we're not matcing "/foobar" and "/foo" if (match && path.length() != topmostPath.length()) { Index: java/org/apache/commons/httpclient/cookie/IgnoreCookiesSpec.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/cookie/IgnoreCookiesSpec.java,v retrieving revision 1.3 diff -u -r1.3 IgnoreCookiesSpec.java --- java/org/apache/commons/httpclient/cookie/IgnoreCookiesSpec.java 18 Apr 2004 23:51:37 -0000 1.3 +++ java/org/apache/commons/httpclient/cookie/IgnoreCookiesSpec.java 25 Apr 2004 20:44:46 -0000 @@ -119,4 +119,18 @@ throws MalformedCookieException, IllegalArgumentException { } + /** + * @return false + */ + public boolean domainMatch(final String host, final String domain) { + return false; + } + + /** + * @return false + */ + public boolean pathMatch(final String path, final String topmostPath) { + return false; + } + } Index: java/org/apache/commons/httpclient/cookie/RFC2109Spec.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/cookie/RFC2109Spec.java,v retrieving revision 1.18 diff -u -r1.18 RFC2109Spec.java --- java/org/apache/commons/httpclient/cookie/RFC2109Spec.java 25 Apr 2004 11:57:39 -0000 1.18 +++ java/org/apache/commons/httpclient/cookie/RFC2109Spec.java 25 Apr 2004 20:44:47 -0000 @@ -1,5 +1,5 @@ /* - * $Header: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/cookie/RFC2109Spec.java,v 1.18 2004/04/25 11:57:39 olegk Exp $ + * $Header: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/cookie/RFC2109Spec.java,v 1.18 2004/04/25 11:57:39 olegk Exp $ * $Revision: 1.18 $ * $Date: 2004/04/25 11:57:39 $ * @@ -162,6 +162,18 @@ } } + /** + * Performs domain-match as defined by the RFC2109. + * @param host The target host. + * @param domain The cookie domain attribute. + * @return true if the specified host matches the given domain. + */ + public boolean domainMatch(String host, String domain) { + boolean match = host.equals(domain) + || (domain.startsWith(".") && host.endsWith(domain)); + + return match; + } /** * Return a name/value string suitable for sending in a "Cookie" @@ -267,4 +279,5 @@ } return buffer.toString(); } + } Index: test/org/apache/commons/httpclient/cookie/TestCookieCompatibilitySpec.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/cookie/TestCookieCompatibilitySpec.java,v retrieving revision 1.4 diff -u -r1.4 TestCookieCompatibilitySpec.java --- test/org/apache/commons/httpclient/cookie/TestCookieCompatibilitySpec.java 25 Apr 2004 11:57:39 -0000 1.4 +++ test/org/apache/commons/httpclient/cookie/TestCookieCompatibilitySpec.java 25 Apr 2004 20:44:51 -0000 @@ -778,8 +778,7 @@ } /** - * Tests if that invalid second domain level cookie gets - * rejected in the strict mode, but gets accepted in the + * Tests if invalid second domain level cookie gets accepted in the * browser compatibility mode. */ public void testSecondDomainLevelCookie() throws Exception { @@ -937,6 +936,16 @@ assertEquals("name1", matched[0].getName()); assertEquals("name2", matched[1].getName()); assertEquals("name3", matched[2].getName()); + } + + public void testInvalidMatchDomain() throws Exception { + Cookie cookie = new Cookie("beta.gamma.com", "name", null, "/", null, false); + cookie.setDomainAttributeSpecified(true); + cookie.setPathAttributeSpecified(true); + + CookieSpec cookiespec = new CookieSpecBase(); + cookiespec.validate("alpha.beta.gamma.com", 80, "/", false, cookie); + assertTrue(cookiespec.match("alpha.beta.gamma.com", 80, "/", false, cookie)); } public void testFormatInvalidCookie() throws Exception { Index: test/org/apache/commons/httpclient/cookie/TestCookieIgnoreSpec.java =================================================================== RCS file: /home/cvspublic/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/cookie/TestCookieIgnoreSpec.java,v retrieving revision 1.2 diff -u -r1.2 TestCookieIgnoreSpec.java --- test/org/apache/commons/httpclient/cookie/TestCookieIgnoreSpec.java 25 Apr 2004 11:57:39 -0000 1.2 +++ test/org/apache/commons/httpclient/cookie/TestCookieIgnoreSpec.java 25 Apr 2004 20:44:51 -0000 @@ -1,5 +1,5 @@ /* - * $Header: /home/cvspublic/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/cookie/TestCookieIgnoreSpec.java,v 1.2 2004/04/25 11:57:39 olegk Exp $ + * $Header: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/cookie/TestCookieIgnoreSpec.java,v 1.2 2004/04/25 11:57:39 olegk Exp $ * $Revision: 1.2 $ * $Date: 2004/04/25 11:57:39 $ * ==================================================================== @@ -103,6 +103,9 @@ cookiespec.parse("host", 80, "/", false, (Header)null); cookiespec.validate("host", 80, "/", false, (Cookie)null); cookiespec.match("host", 80, "/", false, (Cookie)null); + cookiespec.match("host", 80, "/", false, (Cookie [])null); + cookiespec.domainMatch(null, null); + cookiespec.pathMatch(null, null); cookiespec.match("host", 80, "/", false, (Cookie [])null); cookiespec.formatCookie(null); cookiespec.formatCookies(null);