Skip to content

Commit bb8996f

Browse files
author
loewis
committed
Patch #1117454: Remove code to special-case cookies without values
in LWPCookieJar. Backported to 2.4. git-svn-id: http://svn.python.org/projects/python/trunk@38544 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent 0d3034a commit bb8996f

5 files changed

Lines changed: 26 additions & 12 deletions

File tree

Lib/_LWPCookieJar.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,6 @@ def _really_load(self, f, filename, ignore_discard, ignore_expires):
115115

116116
for data in split_header_words([line]):
117117
name, value = data[0]
118-
# name and value are an exception here, since a plain "foo"
119-
# (with no "=", unlike "bar=foo") means a cookie with no
120-
# name and value "foo". With all other cookie-attributes,
121-
# the situation is reversed: "foo" means an attribute named
122-
# "foo" with no value!
123-
if value is None:
124-
name, value = value, name
125118
standard = {}
126119
rest = {}
127120
for k in boolean_attrs:

Lib/_MozillaCookieJar.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ def _really_load(self, f, filename, ignore_discard, ignore_expires):
7373
secure = (secure == "TRUE")
7474
domain_specified = (domain_specified == "TRUE")
7575
if name == "":
76+
# cookies.txt regards 'Set-Cookie: foo' as a cookie
77+
# with no name, whereas cookielib regards it as a
78+
# cookie with no value.
7679
name = value
7780
value = None
7881

Lib/cookielib.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -451,11 +451,7 @@ def parse_ns_headers(ns_headers):
451451
param = param.rstrip()
452452
if param == "": continue
453453
if "=" not in param:
454-
if param.lower() in known_attrs:
455-
k, v = param, None
456-
else:
457-
# cookie with missing value
458-
k, v = param, None
454+
k, v = param, None
459455
else:
460456
k, v = re.split(r"\s*=\s*", param, 1)
461457
k = k.lstrip()

Lib/test/test_cookielib.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,24 @@ def _interact(cookiejar, url, set_cookie_hdrs, hdr_name):
231231
return cookie_hdr
232232

233233

234+
class FileCookieJarTests(TestCase):
235+
def test_lwp_valueless_cookie(self):
236+
# cookies with no value should be saved and loaded consistently
237+
from cookielib import LWPCookieJar
238+
filename = test_support.TESTFN
239+
c = LWPCookieJar()
240+
interact_netscape(c, "http://www.acme.com/", 'boo')
241+
self.assertEqual(c._cookies["www.acme.com"]["/"]["boo"].value, None)
242+
try:
243+
c.save(filename, ignore_discard=True)
244+
c = LWPCookieJar()
245+
c.load(filename, ignore_discard=True)
246+
finally:
247+
try: os.unlink(filename)
248+
except OSError: pass
249+
self.assertEqual(c._cookies["www.acme.com"]["/"]["boo"].value, None)
250+
251+
234252
class CookieTests(TestCase):
235253
# XXX
236254
# Get rid of string comparisons where not actually testing str / repr.
@@ -1636,6 +1654,7 @@ def test_main(verbose=None):
16361654
DateTimeTests,
16371655
HeaderTests,
16381656
CookieTests,
1657+
FileCookieJarTests,
16391658
LWPCookieTests,
16401659
)
16411660

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ Extension Modules
6161
Library
6262
-------
6363

64+
- Patch #1117454: Remove code to special-case cookies without values
65+
in LWPCookieJar.
66+
6467
- Patch #1117339: Add cookielib special name tests.
6568

6669
- Patch #1112812: Make bsddb/__init__.py more friendly for modulefinder.

0 commit comments

Comments
 (0)