diff --git a/ChangeLog b/ChangeLog index 895e6514..c0f0d25a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -86,6 +86,8 @@ + Allow spaces in attribute values. Example: "Set-Cookie: expires=Wed, 12-Dec-2001 19:27:57 GMT" is now parsed correctly + + Add an optional leading dot for domain names, and account for that + in the domain checking routine. Type: feature Changed: linkcheck/cookies.py diff --git a/linkcheck/cookies.py b/linkcheck/cookies.py index eef0ed85..8d5ea9a7 100644 --- a/linkcheck/cookies.py +++ b/linkcheck/cookies.py @@ -152,10 +152,16 @@ class HttpCookie (object): return False cdomain = self.attributes["domain"] if domain == cdomain: + # equality matches + return True + if "." not in domain and domain == cdomain[1:]: + # "localhost" and ".localhost" match return True if not domain.endswith(cdomain): + # any suffix matches return False if "." in domain[:-len(cdomain)]: + # prefix must be dot-free return False return True @@ -185,9 +191,11 @@ class HttpCookie (object): if key == "domain": value = value.lower() if not value.startswith("."): - raise CookieError("domain has no leading dot: %r" % value) - if not has_embedded_dot(value): - raise CookieError("domain has no embedded dot: %r" % value) + if not has_embedded_dot(value): + if "." in value: + raise CookieError("invalid dot in domain %r" % value) + # supply a leading dot + value = "."+value if key == "max-age": try: num = int(value) diff --git a/linkcheck/tests/test_cookies.py b/linkcheck/tests/test_cookies.py index 5e889a77..4af4d31a 100644 --- a/linkcheck/tests/test_cookies.py +++ b/linkcheck/tests/test_cookies.py @@ -77,6 +77,7 @@ class TestCookies (unittest.TestCase): def test_netscape_cookie4 (self): data = ( ("Foo", "Bar\""), + ("Domain", "localhost"), ("Port", "100,555,76"), ) parts = ['%s="%s"' % (key, value) for key, value in data] @@ -89,6 +90,7 @@ class TestCookies (unittest.TestCase): def test_netscape_cookie5 (self): data = ( ("Foo", "Bar"), + ("Domain", "imadoofus.org"), ("Expires", "Wed, 12-Dec-2001 19:27:57 GMT"), ("Path", "/"), )