]> granicus.if.org Git - python/commitdiff
Patch #1117454: Remove code to special-case cookies without values
authorMartin v. Löwis <martin@v.loewis.de>
Thu, 3 Mar 2005 10:57:37 +0000 (10:57 +0000)
committerMartin v. Löwis <martin@v.loewis.de>
Thu, 3 Mar 2005 10:57:37 +0000 (10:57 +0000)
in LWPCookieJar. Backported to 2.4.

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

index 2c8d4564e0b3cb6cb2f880df1271f2e965663586..25a25286ab104153af7b06d9334eed2390649d38 100644 (file)
@@ -115,13 +115,6 @@ class LWPCookieJar(FileCookieJar):
 
                 for data in split_header_words([line]):
                     name, value = data[0]
-                    # name and value are an exception here, since a plain "foo"
-                    # (with no "=", unlike "bar=foo") means a cookie with no
-                    # name and value "foo".  With all other cookie-attributes,
-                    # the situation is reversed: "foo" means an attribute named
-                    # "foo" with no value!
-                    if value is None:
-                        name, value = value, name
                     standard = {}
                     rest = {}
                     for k in boolean_attrs:
index 0e08c09d6cb23f426b97cda35848ec198de8a01b..88e8492504b59f5b8ad67eb9e2d6fc96a5753202 100644 (file)
@@ -73,6 +73,9 @@ class MozillaCookieJar(FileCookieJar):
                 secure = (secure == "TRUE")
                 domain_specified = (domain_specified == "TRUE")
                 if name == "":
+                    # cookies.txt regards 'Set-Cookie: foo' as a cookie
+                    # with no name, whereas cookielib regards it as a
+                    # cookie with no value.
                     name = value
                     value = None
 
index 49989b436e9b76f15ac8796782aae142b5366a48..42a2513fec89362f105bca810d726d61aefbb3ae 100644 (file)
@@ -451,11 +451,7 @@ def parse_ns_headers(ns_headers):
             param = param.rstrip()
             if param == "": continue
             if "=" not in param:
-                if param.lower() in known_attrs:
-                    k, v = param, None
-                else:
-                    # cookie with missing value
-                    k, v = param, None
+                k, v = param, None
             else:
                 k, v = re.split(r"\s*=\s*", param, 1)
                 k = k.lstrip()
index 679e3aa8166f714a4fc15b6efe9afdfb84dadf2b..78283262506f8317703d1c17ea548199c56a7f78 100644 (file)
@@ -231,6 +231,24 @@ def _interact(cookiejar, url, set_cookie_hdrs, hdr_name):
     return cookie_hdr
 
 
+class FileCookieJarTests(TestCase):
+    def test_lwp_valueless_cookie(self):
+        # cookies with no value should be saved and loaded consistently
+        from cookielib import LWPCookieJar
+        filename = test_support.TESTFN
+        c = LWPCookieJar()
+        interact_netscape(c, "http://www.acme.com/", 'boo')
+        self.assertEqual(c._cookies["www.acme.com"]["/"]["boo"].value, None)
+        try:
+            c.save(filename, ignore_discard=True)
+            c = LWPCookieJar()
+            c.load(filename, ignore_discard=True)
+        finally:
+            try: os.unlink(filename)
+            except OSError: pass
+        self.assertEqual(c._cookies["www.acme.com"]["/"]["boo"].value, None)
+
+
 class CookieTests(TestCase):
     # XXX
     # Get rid of string comparisons where not actually testing str / repr.
@@ -1636,6 +1654,7 @@ def test_main(verbose=None):
         DateTimeTests,
         HeaderTests,
         CookieTests,
+        FileCookieJarTests,
         LWPCookieTests,
         )
 
index df044f41390cd61b620840f82420cbcb74026cc2..cdb9f8004b7e5b8cbc1d06b3d16e3ecade00c1bc 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -61,6 +61,9 @@ Extension Modules
 Library
 -------
 
+- Patch #1117454: Remove code to special-case cookies without values
+  in LWPCookieJar.
+
 - Patch #1117339: Add cookielib special name tests.
 
 - Patch #1112812: Make bsddb/__init__.py more friendly for modulefinder.