Skip to content

Commit

Permalink
Fix off-by-one error in cookie domain matching code.
Browse files Browse the repository at this point in the history
  • Loading branch information
calvin committed Jul 13, 2008
1 parent 97cf700 commit 7b2a21c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
6 changes: 6 additions & 0 deletions ChangeLog.txt
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion linkcheck/cookies.py
Expand Up @@ -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
Expand Down
24 changes: 18 additions & 6 deletions tests/test_cookies.py
Expand Up @@ -23,9 +23,7 @@


class TestCookies (unittest.TestCase):
"""
Test list dictionary routines.
"""
"""Test cookie routines."""

def test_netscape_cookie1 (self):
data = (
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 7b2a21c

Please sign in to comment.