mirror of
https://github.com/Hopiu/linkchecker.git
synced 2026-04-22 15:14:44 +00:00
Allow spaces in cookie values
git-svn-id: https://linkchecker.svn.sourceforge.net/svnroot/linkchecker/trunk/linkchecker@3636 e7d03fd6-7b0d-0410-9947-9c21f3af8025
This commit is contained in:
parent
7b6ca18034
commit
fddf890bd4
3 changed files with 41 additions and 1 deletions
|
|
@ -82,6 +82,13 @@
|
|||
Changed: config/create.sql
|
||||
Closes: SF #1849733
|
||||
|
||||
* Improved cookie parsing:
|
||||
+ Allow spaces in attribute values. Example:
|
||||
"Set-Cookie: expires=Wed, 12-Dec-2001 19:27:57 GMT"
|
||||
is now parsed correctly
|
||||
Type: feature
|
||||
Changed: linkcheck/cookies.py
|
||||
|
||||
4.7 "300" (released 17.6.2007)
|
||||
|
||||
* Mention in the documentation that --anchors enables logging of
|
||||
|
|
|
|||
|
|
@ -47,6 +47,24 @@ unquote = Cookie._unquote
|
|||
quote = Cookie._quote
|
||||
has_embedded_dot = re.compile(r"[a-zA-Z0-9]\.[a-zA-Z]").search
|
||||
|
||||
|
||||
# Pattern for finding cookie snatched from Pythons Cookie.py
|
||||
# Modification: allow whitespace in values.
|
||||
LegalChars = r"\w\d!#%&'~_`><@,:/\$\*\+\-\.\^\|\)\(\?\}\{\="
|
||||
CookiePattern = re.compile(r"""
|
||||
(?P<key> # Start of group 'key'
|
||||
[%(legalchars)s]+? # Any word of at least one letter, nongreedy
|
||||
) # End of group 'key'
|
||||
\s*=\s* # Equal Sign
|
||||
(?P<val> # Start of group 'val'
|
||||
"(?:[^\\"]|\\.)*" # Any doublequoted string
|
||||
| # or
|
||||
[%(legalchars)s\s]* # Any word or empty string
|
||||
) # End of group 'val'
|
||||
\s*;? # Probably ending in a semi-colon
|
||||
""" % {"legalchars": LegalChars}, re.VERBOSE)
|
||||
|
||||
|
||||
class HttpCookie (object):
|
||||
"""
|
||||
A cookie consists of one name-value pair with attributes.
|
||||
|
|
@ -188,7 +206,7 @@ class HttpCookie (object):
|
|||
raise CookieError("invalid port number: %r" % port)
|
||||
self.attributes[key] = value
|
||||
|
||||
def parse (self, text, patt=Cookie._CookiePattern):
|
||||
def parse (self, text, patt=CookiePattern):
|
||||
text = strformat.ascii_safe(text)
|
||||
# reset values
|
||||
self.name = None
|
||||
|
|
|
|||
|
|
@ -86,6 +86,21 @@ class TestCookies (unittest.TestCase):
|
|||
path = "/"
|
||||
cookie = linkcheck.cookies.NetscapeCookie(value, scheme, host, path)
|
||||
|
||||
def test_netscape_cookie5 (self):
|
||||
data = (
|
||||
("Foo", "Bar"),
|
||||
("Expires", "Wed, 12-Dec-2001 19:27:57 GMT"),
|
||||
("Path", "/"),
|
||||
)
|
||||
# note: values are without quotes
|
||||
parts = ['%s=%s' % (key, value) for key, value in data]
|
||||
value = "; ".join(parts)
|
||||
scheme = "http"
|
||||
host = "imadoofus.org"
|
||||
path = "/"
|
||||
cookie = linkcheck.cookies.NetscapeCookie(value, scheme, host, path)
|
||||
self.assert_(cookie.is_expired())
|
||||
|
||||
def test_rfc_cookie1 (self):
|
||||
data = (
|
||||
("Foo", "Bar"),
|
||||
|
|
|
|||
Loading…
Reference in a new issue