diff --git a/ChangeLog.txt b/ChangeLog.txt index a6a19a141..d577c5e99 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -61,6 +61,12 @@ Type: bugfix Changed: linkcheck/robotparser2.py + * Fix off-by-one error in cookie domain matching code. Prevented + some cookie files to work properly. + Type: bugfix + Changed: linkcheck/cookies.py + Closes: SF bug #2016451 + 4.9 "Michael Clayton" (released 25.4.2008) * Parse Shockwave Flash (SWF) for URLs to check diff --git a/linkcheck/cookies.py b/linkcheck/cookies.py index d90030407..47943c6ba 100644 --- a/linkcheck/cookies.py +++ b/linkcheck/cookies.py @@ -155,7 +155,7 @@ def check_domain (self, domain): if not domain.endswith(cdomain): # any suffix matches return False - if "." in domain[:-len(cdomain)]: + if "." in domain[:-(len(cdomain)+1)]: # prefix must be dot-free return False return True diff --git a/tests/test_cookies.py b/tests/test_cookies.py index 9f1eb4911..b13a727e3 100644 --- a/tests/test_cookies.py +++ b/tests/test_cookies.py @@ -23,9 +23,7 @@ class TestCookies (unittest.TestCase): - """ - Test list dictionary routines. - """ + """Test cookie routines.""" def test_netscape_cookie1 (self): data = ( @@ -99,6 +97,22 @@ def test_netscape_cookie5 (self): cookie = linkcheck.cookies.NetscapeCookie(value, scheme, host, path) self.assert_(cookie.is_expired()) + def test_netscape_cookie6 (self): + data = ( + ("Foo", "Bar"), + ("Domain", "example.org"), + ("Path", "/"), + ) + # note: values are without quotes + value = "; ".join('%s=%s' % (key, value) for key, value in data) + scheme = "http" + host = "example.org" + path = "/" + cookie = linkcheck.cookies.NetscapeCookie(value, scheme, host, path) + self.assertTrue(cookie.is_valid_for("http", "example.org", 80, "/")) + self.assertTrue(cookie.is_valid_for("http", "www.example.org", 80, "/")) + self.assertFalse(cookie.is_valid_for("http", "www.b.example.org", 80, "/")) + def test_rfc_cookie1 (self): data = ( ("Foo", "Bar"), @@ -199,9 +213,7 @@ def test_cookie_parse4 (self): def test_suite (): - """ - Build and return a TestSuite. - """ + """Build and return a TestSuite.""" suite = unittest.TestSuite() suite.addTest(unittest.makeSuite(TestCookies)) return suite