summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2005-03-03 10:47:38 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2005-03-03 10:47:38 (GMT)
commita8fd7e96e237b356767edb6e419bb93e0b22740a (patch)
tree7af43369a7f3017c930cd2a4c03adc82214e5882 /Lib
parent4338765912a100372017c6149ffc25bc425b6d26 (diff)
downloadcpython-a8fd7e96e237b356767edb6e419bb93e0b22740a.zip
cpython-a8fd7e96e237b356767edb6e419bb93e0b22740a.tar.gz
cpython-a8fd7e96e237b356767edb6e419bb93e0b22740a.tar.bz2
Patch #1117339: Add cookielib special name tests.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/cookielib.py4
-rw-r--r--Lib/test/test_cookielib.py29
2 files changed, 28 insertions, 5 deletions
diff --git a/Lib/cookielib.py b/Lib/cookielib.py
index 86479f8..6a9b342 100644
--- a/Lib/cookielib.py
+++ b/Lib/cookielib.py
@@ -448,7 +448,7 @@ def parse_ns_headers(ns_headers):
for ns_header in ns_headers:
pairs = []
version_set = False
- for param in re.split(r";\s*", ns_header):
+ for ii, param in enumerate(re.split(r";\s*", ns_header)):
param = param.rstrip()
if param == "": continue
if "=" not in param:
@@ -460,7 +460,7 @@ def parse_ns_headers(ns_headers):
else:
k, v = re.split(r"\s*=\s*", param, 1)
k = k.lstrip()
- if k is not None:
+ if ii != 0:
lc = k.lower()
if lc in known_attrs:
k = lc
diff --git a/Lib/test/test_cookielib.py b/Lib/test/test_cookielib.py
index 72c9fc8..679e3aa 100644
--- a/Lib/test/test_cookielib.py
+++ b/Lib/test/test_cookielib.py
@@ -103,13 +103,23 @@ class HeaderTests(TestCase):
from cookielib import parse_ns_headers
# quotes should be stripped
- expected = [[('expires', 2209069412L), ('version', '0')]]
+ expected = [[('foo', 'bar'), ('expires', 2209069412L), ('version', '0')]]
for hdr in [
- 'expires=01 Jan 2040 22:23:32 GMT',
- 'expires="01 Jan 2040 22:23:32 GMT"',
+ 'foo=bar; expires=01 Jan 2040 22:23:32 GMT',
+ 'foo=bar; expires="01 Jan 2040 22:23:32 GMT"',
]:
self.assertEquals(parse_ns_headers([hdr]), expected)
+ def test_parse_ns_headers_special_names(self):
+ # names such as 'expires' are not special in first name=value pair
+ # of Set-Cookie: header
+ from cookielib import parse_ns_headers
+
+ # Cookie with name 'expires'
+ hdr = 'expires=01 Jan 2040 22:23:32 GMT'
+ expected = [[("expires", "01 Jan 2040 22:23:32 GMT"), ("version", "0")]]
+ self.assertEquals(parse_ns_headers([hdr]), expected)
+
def test_join_header_words(self):
from cookielib import join_header_words
@@ -370,6 +380,19 @@ class CookieTests(TestCase):
self.assert_(foo.expires is None)
self.assert_(spam.expires is None)
+ def test_ns_parser_special_names(self):
+ # names such as 'expires' are not special in first name=value pair
+ # of Set-Cookie: header
+ from cookielib import CookieJar
+
+ c = CookieJar()
+ interact_netscape(c, "http://www.acme.com/", 'expires=eggs')
+ interact_netscape(c, "http://www.acme.com/", 'version=eggs; spam=eggs')
+
+ cookies = c._cookies["www.acme.com"]["/"]
+ self.assert_('expires' in cookies)
+ self.assert_('version' in cookies)
+
def test_expires(self):
from cookielib import time2netscape, CookieJar