]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
allow square brackets in cookie values (#22931)
authorBenjamin Peterson <benjamin@python.org>
Sat, 23 May 2015 15:46:25 +0000 (10:46 -0500)
committerBenjamin Peterson <benjamin@python.org>
Sat, 23 May 2015 15:46:25 +0000 (10:46 -0500)
Lib/Cookie.py
Lib/test/test_cookie.py
Misc/NEWS

index 0b15531196b833944e5f761d2fe653ab26b76cdb..b1704d98ccf191f7d9e1f345d1102616dfb4030d 100644 (file)
@@ -528,12 +528,13 @@ class Morsel(dict):
 # 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<key>"                   # 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 @@ _CookiePattern = re.compile(
     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.
index 36cd52e58fec2c2a4b822378d947f27de1e442cf..404190123fae9983eccb331eb3aa1c26ed1ab326 100644 (file)
@@ -27,6 +27,20 @@ class CookieTests(unittest.TestCase):
               'dict': {'keebler' : 'E=mc2'},
               'repr': "<SimpleCookie: keebler='E=mc2'>",
               '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': "<SimpleCookie: a='b' c='[' d='r' f='h'>",
+                'output': '\n'.join((
+                    'Set-Cookie: a=b',
+                    'Set-Cookie: c=[',
+                    'Set-Cookie: d=r',
+                    'Set-Cookie: f=h'
+                ))
             }
         ]
 
index aef5e59536d37d8a143af371db5baeaa36c9e19f..c311f6b25d997ad67231f596933c40f8c64fd998 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -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?
 ================================================