diff options
author | Benjamin Peterson <benjamin@python.org> | 2010-06-27 21:45:24 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2010-06-27 21:45:24 (GMT) |
commit | 3e5cd1d04e8a39130752a1e888707a68a2943274 (patch) | |
tree | 8108e5e2b0bc0059f4d7ae3ec11e59df69e5015f /Lib/http/cookiejar.py | |
parent | 63eebe5318e2da467d6a57eae12083dbc14f31e4 (diff) | |
download | cpython-3e5cd1d04e8a39130752a1e888707a68a2943274.zip cpython-3e5cd1d04e8a39130752a1e888707a68a2943274.tar.gz cpython-3e5cd1d04e8a39130752a1e888707a68a2943274.tar.bz2 |
Merged revisions 81465-81466,81468,81679,81735,81760,81868,82183 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r81465 | georg.brandl | 2010-05-22 06:29:19 -0500 (Sat, 22 May 2010) | 2 lines
Issue #3924: Ignore cookies with invalid "version" field in cookielib.
........
r81466 | georg.brandl | 2010-05-22 06:31:16 -0500 (Sat, 22 May 2010) | 1 line
Underscore the name of an internal utility function.
........
r81468 | georg.brandl | 2010-05-22 06:43:25 -0500 (Sat, 22 May 2010) | 1 line
#8635: document enumerate() start parameter in docstring.
........
r81679 | benjamin.peterson | 2010-06-03 16:21:03 -0500 (Thu, 03 Jun 2010) | 1 line
use a set for membership testing
........
r81735 | michael.foord | 2010-06-05 06:46:59 -0500 (Sat, 05 Jun 2010) | 1 line
Extract error message truncating into a method (unittest.TestCase._truncateMessage).
........
r81760 | michael.foord | 2010-06-05 14:38:42 -0500 (Sat, 05 Jun 2010) | 1 line
Issue 8302. SkipTest exception is setUpClass or setUpModule is now reported as a skip rather than an error.
........
r81868 | benjamin.peterson | 2010-06-09 14:45:04 -0500 (Wed, 09 Jun 2010) | 1 line
fix code formatting
........
r82183 | benjamin.peterson | 2010-06-23 15:29:26 -0500 (Wed, 23 Jun 2010) | 1 line
cpython only gc tests
........
Diffstat (limited to 'Lib/http/cookiejar.py')
-rw-r--r-- | Lib/http/cookiejar.py | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/Lib/http/cookiejar.py b/Lib/http/cookiejar.py index e9efab8..657faa1 100644 --- a/Lib/http/cookiejar.py +++ b/Lib/http/cookiejar.py @@ -436,6 +436,13 @@ def join_header_words(lists): if attr: headers.append("; ".join(attr)) return ", ".join(headers) +def strip_quotes(text): + if text.startswith('"'): + text = text[1:] + if text.endswith('"'): + text = text[:-1] + return text + def parse_ns_headers(ns_headers): """Ad-hoc parser for Netscape protocol cookie-attributes. @@ -453,7 +460,7 @@ def parse_ns_headers(ns_headers): """ known_attrs = ("expires", "domain", "path", "secure", # RFC 2109 attrs (may turn up in Netscape cookies, too) - "port", "max-age") + "version", "port", "max-age") result = [] for ns_header in ns_headers: @@ -473,12 +480,11 @@ def parse_ns_headers(ns_headers): k = lc if k == "version": # This is an RFC 2109 cookie. + v = strip_quotes(v) version_set = True if k == "expires": # convert expires date to seconds since epoch - if v.startswith('"'): v = v[1:] - if v.endswith('"'): v = v[:-1] - v = http2time(v) # None if invalid + v = http2time(strip_quotes(v)) # None if invalid pairs.append((k, v)) if pairs: @@ -1446,7 +1452,11 @@ class CookieJar: # set the easy defaults version = standard.get("version", None) - if version is not None: version = int(version) + if version is not None: + try: + version = int(version) + except ValueError: + return None # invalid version, ignore cookie secure = standard.get("secure", False) # (discard is also set if expires is Absent) discard = standard.get("discard", False) |