Skip to content

Commit 0d3034a

Browse files
author
loewis
committed
Patch #1117339: Add cookielib special name tests.
Backported to 2.4. git-svn-id: http://svn.python.org/projects/python/trunk@38542 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent 4b5757b commit 0d3034a

3 files changed

Lines changed: 30 additions & 5 deletions

File tree

Lib/cookielib.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ def parse_ns_headers(ns_headers):
447447
for ns_header in ns_headers:
448448
pairs = []
449449
version_set = False
450-
for param in re.split(r";\s*", ns_header):
450+
for ii, param in enumerate(re.split(r";\s*", ns_header)):
451451
param = param.rstrip()
452452
if param == "": continue
453453
if "=" not in param:
@@ -459,7 +459,7 @@ def parse_ns_headers(ns_headers):
459459
else:
460460
k, v = re.split(r"\s*=\s*", param, 1)
461461
k = k.lstrip()
462-
if k is not None:
462+
if ii != 0:
463463
lc = k.lower()
464464
if lc in known_attrs:
465465
k = lc

Lib/test/test_cookielib.py

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,23 @@ def test_parse_ns_headers(self):
103103
from cookielib import parse_ns_headers
104104

105105
# quotes should be stripped
106-
expected = [[('expires', 2209069412L), ('version', '0')]]
106+
expected = [[('foo', 'bar'), ('expires', 2209069412L), ('version', '0')]]
107107
for hdr in [
108-
'expires=01 Jan 2040 22:23:32 GMT',
109-
'expires="01 Jan 2040 22:23:32 GMT"',
108+
'foo=bar; expires=01 Jan 2040 22:23:32 GMT',
109+
'foo=bar; expires="01 Jan 2040 22:23:32 GMT"',
110110
]:
111111
self.assertEquals(parse_ns_headers([hdr]), expected)
112112

113+
def test_parse_ns_headers_special_names(self):
114+
# names such as 'expires' are not special in first name=value pair
115+
# of Set-Cookie: header
116+
from cookielib import parse_ns_headers
117+
118+
# Cookie with name 'expires'
119+
hdr = 'expires=01 Jan 2040 22:23:32 GMT'
120+
expected = [[("expires", "01 Jan 2040 22:23:32 GMT"), ("version", "0")]]
121+
self.assertEquals(parse_ns_headers([hdr]), expected)
122+
113123
def test_join_header_words(self):
114124
from cookielib import join_header_words
115125

@@ -370,6 +380,19 @@ def test_ns_parser(self):
370380
self.assert_(foo.expires is None)
371381
self.assert_(spam.expires is None)
372382

383+
def test_ns_parser_special_names(self):
384+
# names such as 'expires' are not special in first name=value pair
385+
# of Set-Cookie: header
386+
from cookielib import CookieJar
387+
388+
c = CookieJar()
389+
interact_netscape(c, "http://www.acme.com/", 'expires=eggs')
390+
interact_netscape(c, "http://www.acme.com/", 'version=eggs; spam=eggs')
391+
392+
cookies = c._cookies["www.acme.com"]["/"]
393+
self.assert_('expires' in cookies)
394+
self.assert_('version' in cookies)
395+
373396
def test_expires(self):
374397
from cookielib import time2netscape, CookieJar
375398

Misc/NEWS

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

64+
- Patch #1117339: Add cookielib special name tests.
65+
6466
- Patch #1112812: Make bsddb/__init__.py more friendly for modulefinder.
6567

6668
- Patch #1110248: SYNC_FLUSH the zlib buffer for GZipFile.flush.

0 commit comments

Comments
 (0)