Skip to content

Commit d504f20

Browse files
committed
merge 3.2 (#22931)
2 parents deff2b7 + 9bd476e commit d504f20

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

Lib/http/cookies.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -428,12 +428,13 @@ def OutputString(self, attrs=None):
428428
# result, the parsing rules here are less strict.
429429
#
430430

431-
_LegalCharsPatt = r"[\w\d!#%&'~_`><@,:/\$\*\+\-\.\^\|\)\(\?\}\{\=]"
431+
_LegalKeyChars = r"\w\d!#%&'~_`><@,:/\$\*\+\-\.\^\|\)\(\?\}\{\="
432+
_LegalValueChars = _LegalKeyChars + '\[\]'
432433
_CookiePattern = re.compile(r"""
433434
(?x) # This is a verbose pattern
434435
\s* # Optional whitespace at start of cookie
435436
(?P<key> # Start of group 'key'
436-
""" + _LegalCharsPatt + r"""+? # Any word of at least one letter
437+
[""" + _LegalKeyChars + r"""]+? # Any word of at least one letter
437438
) # End of group 'key'
438439
( # Optional group: there may not be a value.
439440
\s*=\s* # Equal Sign
@@ -442,7 +443,7 @@ def OutputString(self, attrs=None):
442443
| # or
443444
\w{3},\s[\w\d\s-]{9,11}\s[\d:]{8}\sGMT # Special case for "expires" attr
444445
| # or
445-
""" + _LegalCharsPatt + r"""* # Any word or empty string
446+
[""" + _LegalValueChars + r"""]* # Any word or empty string
446447
) # End of group 'val'
447448
)? # End of optional value group
448449
\s* # Any number of spaces.

Lib/test/test_http_cookies.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,19 @@ def test_basic(self):
4343
'repr': "<SimpleCookie: key:term='value:term'>",
4444
'output': 'Set-Cookie: key:term=value:term'},
4545

46+
# issue22931 - Adding '[' and ']' as valid characters in cookie
47+
# values as defined in RFC 6265
48+
{
49+
'data': 'a=b; c=[; d=r; f=h',
50+
'dict': {'a':'b', 'c':'[', 'd':'r', 'f':'h'},
51+
'repr': "<SimpleCookie: a='b' c='[' d='r' f='h'>",
52+
'output': '\n'.join((
53+
'Set-Cookie: a=b',
54+
'Set-Cookie: c=[',
55+
'Set-Cookie: d=r',
56+
'Set-Cookie: f=h'
57+
))
58+
}
4659
]
4760

4861
for case in cases:

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ Core and Builtins
2222
Library
2323
-------
2424

25+
- Issue #22931: Allow '[' and ']' in cookie values.
26+
2527
- Issue #24094: Fix possible crash in json.encode with poorly behaved dict
2628
subclasses.
2729

0 commit comments

Comments
 (0)