mirror of
https://github.com/Hopiu/linkchecker.git
synced 2026-04-02 22:20:23 +00:00
Add optional leading dot for cookie domain value
git-svn-id: https://linkchecker.svn.sourceforge.net/svnroot/linkchecker/trunk/linkchecker@3637 e7d03fd6-7b0d-0410-9947-9c21f3af8025
This commit is contained in:
parent
fddf890bd4
commit
6c07be042d
3 changed files with 15 additions and 3 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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", "/"),
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in a new issue