]> granicus.if.org Git - python/commitdiff
Patch #1117339: Add cookielib special name tests.
authorMartin v. Löwis <martin@v.loewis.de>
Thu, 3 Mar 2005 10:48:12 +0000 (10:48 +0000)
committerMartin v. Löwis <martin@v.loewis.de>
Thu, 3 Mar 2005 10:48:12 +0000 (10:48 +0000)
Backported to 2.4.

Lib/cookielib.py
Lib/test/test_cookielib.py
Misc/NEWS

index 7fec8584fe3e697ec6a0f86d991ba46693729eb1..49989b436e9b76f15ac8796782aae142b5366a48 100644 (file)
@@ -447,7 +447,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:
@@ -459,7 +459,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
index 72c9fc824a8cc2212001862c2639031e9c837587..679e3aa8166f714a4fc15b6efe9afdfb84dadf2b 100644 (file)
@@ -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
 
index a313d6e64df786dd537fe143b8a5cc852bef34b5..df044f41390cd61b620840f82420cbcb74026cc2 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -61,6 +61,8 @@ Extension Modules
 Library
 -------
 
+- Patch #1117339: Add cookielib special name tests.
+
 - Patch #1112812: Make bsddb/__init__.py more friendly for modulefinder.
 
 - Patch #1110248: SYNC_FLUSH the zlib buffer for GZipFile.flush.