Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Lib/http/cookiejar.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ def join_header_words(lists):
attr = []
for k, v in pairs:
if v is not None:
if not v.isalnum() and '_' not in v:
if not re.search(r"^\w+$", v):
v = HEADER_JOIN_ESCAPE_RE.sub(r"\\\1", v) # escape " and \
v = '"%s"' % v
k = "%s=%s" % (k, v)
Expand Down
22 changes: 17 additions & 5 deletions Lib/test/test_http_cookiejar.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,19 @@ def test_parse_ns_headers_special_names(self):
self.assertEqual(parse_ns_headers([hdr]), expected)

def test_join_header_words(self):
joined = join_header_words([[("foo", None), ("bar", "baz")]])
self.assertEqual(joined, "foo; bar=baz")

self.assertEqual(join_header_words([[]]), "")
for src, expected in [
([[("foo", None), ("bar", "baz")]], "foo; bar=baz"),
(([]), ""),
(([[]]), ""),
(([[("a", "_")]]), "a=_"),
(([[("a", ";")]]), 'a=";"'),
([[("n", None), ("foo", "foo;_")], [("bar", "foo_bar")]],
'n; foo="foo;_", bar=foo_bar'),
([[("n", "m"), ("foo", None)], [("bar", "foo_bar")]],
'n=m; foo, bar=foo_bar'),
]:
with self.subTest(src=src):
self.assertEqual(join_header_words(src), expected)

def test_split_header_words(self):
tests = [
Expand Down Expand Up @@ -286,7 +295,10 @@ def test_roundtrip(self):
'foo=bar; port="80,81"; discard, bar=baz'),

(r'Basic realm="\"foo\\\\bar\""',
r'Basic; realm="\"foo\\\\bar\""')
r'Basic; realm="\"foo\\\\bar\""'),

('n; foo="foo;_", bar=foo!_',
'n; foo="foo;_", bar="foo!_"'),
]

for arg, expect in tests:
Expand Down

This file was deleted.

Loading