changeset: 96234:2a7b0e145945 branch: 2.7 parent: 96216:117af4bc0513 user: Benjamin Peterson date: Sat May 23 10:46:25 2015 -0500 files: Lib/Cookie.py Lib/test/test_cookie.py Misc/NEWS description: allow square brackets in cookie values (#22931) diff -r 117af4bc0513 -r 2a7b0e145945 Lib/Cookie.py --- a/Lib/Cookie.py Fri May 22 17:53:06 2015 -0500 +++ b/Lib/Cookie.py Sat May 23 10:46:25 2015 -0500 @@ -528,12 +528,13 @@ # result, the parsing rules here are less strict. # -_LegalCharsPatt = r"[\w\d!#%&'~_`><@,:/\$\*\+\-\.\^\|\)\(\?\}\{\=]" +_LegalKeyChars = r"\w\d!#%&'~_`><@,:/\$\*\+\-\.\^\|\)\(\?\}\{\=" +_LegalValueChars = _LegalKeyChars + r"\[\]" _CookiePattern = re.compile( r"(?x)" # This is a Verbose pattern r"\s*" # Optional whitespace at start of cookie r"(?P" # Start of group 'key' - ""+ _LegalCharsPatt +"+?" # Any word of at least one letter, nongreedy + "["+ _LegalKeyChars +"]+?" # Any word of at least one letter, nongreedy r")" # End of group 'key' r"(" # Optional group: there may not be a value. r"\s*=\s*" # Equal Sign @@ -542,7 +543,7 @@ r"|" # or r"\w{3},\s[\s\w\d-]{9,11}\s[\d:]{8}\sGMT" # Special case for "expires" attr r"|" # or - ""+ _LegalCharsPatt +"*" # Any word or empty string + "["+ _LegalValueChars +"]*" # Any word or empty string r")" # End of group 'val' r")?" # End of optional value group r"\s*" # Any number of spaces. diff -r 117af4bc0513 -r 2a7b0e145945 Lib/test/test_cookie.py --- a/Lib/test/test_cookie.py Fri May 22 17:53:06 2015 -0500 +++ b/Lib/test/test_cookie.py Sat May 23 10:46:25 2015 -0500 @@ -27,6 +27,20 @@ 'dict': {'keebler' : 'E=mc2'}, 'repr': "", 'output': 'Set-Cookie: keebler=E=mc2', + }, + + # 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' + )) } ] diff -r 117af4bc0513 -r 2a7b0e145945 Misc/NEWS --- a/Misc/NEWS Fri May 22 17:53:06 2015 -0500 +++ b/Misc/NEWS Sat May 23 10:46:25 2015 -0500 @@ -2,6 +2,17 @@ Python News +++++++++++ +What's New in Python 2.7.10? +============================ + +*Release date: 2015-05-23* + +Library +------- + +- Issue #22931: Allow '[' and ']' in cookie values. + + What's New in Python 2.7.10 release candidate 1? ================================================