changeset: 96232:a43f5515e3a2 branch: 3.4 parent: 96225:4c16773052d1 parent: 96231:c7b3a50a2f01 user: Benjamin Peterson date: Sat May 23 10:40:47 2015 -0500 files: Lib/http/cookies.py Lib/test/test_http_cookies.py Misc/NEWS description: merge 3.3 (#22931) diff -r 4c16773052d1 -r a43f5515e3a2 Lib/http/cookies.py --- a/Lib/http/cookies.py Fri May 22 20:30:16 2015 -0400 +++ b/Lib/http/cookies.py Sat May 23 10:40:47 2015 -0500 @@ -428,12 +428,13 @@ # result, the parsing rules here are less strict. # -_LegalCharsPatt = r"[\w\d!#%&'~_`><@,:/\$\*\+\-\.\^\|\)\(\?\}\{\=]" +_LegalKeyChars = r"\w\d!#%&'~_`><@,:/\$\*\+\-\.\^\|\)\(\?\}\{\=" +_LegalValueChars = _LegalKeyChars + '\[\]' _CookiePattern = re.compile(r""" (?x) # This is a verbose pattern \s* # Optional whitespace at start of cookie (?P # Start of group 'key' - """ + _LegalCharsPatt + r"""+? # Any word of at least one letter + [""" + _LegalKeyChars + r"""]+? # Any word of at least one letter ) # End of group 'key' ( # Optional group: there may not be a value. \s*=\s* # Equal Sign @@ -442,7 +443,7 @@ | # or \w{3},\s[\w\d\s-]{9,11}\s[\d:]{8}\sGMT # Special case for "expires" attr | # or - """ + _LegalCharsPatt + r"""* # Any word or empty string + [""" + _LegalValueChars + r"""]* # Any word or empty string ) # End of group 'val' )? # End of optional value group \s* # Any number of spaces. diff -r 4c16773052d1 -r a43f5515e3a2 Lib/test/test_http_cookies.py --- a/Lib/test/test_http_cookies.py Fri May 22 20:30:16 2015 -0400 +++ b/Lib/test/test_http_cookies.py Sat May 23 10:40:47 2015 -0500 @@ -43,6 +43,19 @@ 'repr': "", 'output': 'Set-Cookie: key:term=value:term'}, + # issue22931 - Adding '[' and ']' as valid characters in cookie + # values as defined in RFC 6265 + { + 'data': 'a=b; c=[; d=r; f=h', + 'dict': {'a':'b', 'c':'[', 'd':'r', 'f':'h'}, + 'repr': "", + 'output': '\n'.join(( + 'Set-Cookie: a=b', + 'Set-Cookie: c=[', + 'Set-Cookie: d=r', + 'Set-Cookie: f=h' + )) + } ] for case in cases: diff -r 4c16773052d1 -r a43f5515e3a2 Misc/NEWS --- a/Misc/NEWS Fri May 22 20:30:16 2015 -0400 +++ b/Misc/NEWS Sat May 23 10:40:47 2015 -0500 @@ -80,6 +80,8 @@ - Issue #23796: peek and read1 methods of BufferedReader now raise ValueError if they called on a closed object. Patch by John Hergenroeder. +- Issue #22931: Allow '[' and ']' in cookie values. + - Issue #24094: Fix possible crash in json.encode with poorly behaved dict subclasses.