mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
parent
9b62b39070
commit
4ea3eade51
3 changed files with 30 additions and 5 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue