[Python-checkins] cpython (merge 3.4 -> default): merge 3.4 (#22931)

benjamin.peterson python-checkins at python.org
Sat May 23 17:48:14 CEST 2015


https://hg.python.org/cpython/rev/c58f3e76dc6c
changeset:   96233:c58f3e76dc6c
parent:      96229:7f2e6f236202
parent:      96232:a43f5515e3a2
user:        Benjamin Peterson <benjamin at python.org>
date:        Sat May 23 10:41:30 2015 -0500
summary:
  merge 3.4 (#22931)

files:
  Lib/http/cookies.py           |   7 ++++---
  Lib/test/test_http_cookies.py |  13 +++++++++++++
  Misc/NEWS                     |   2 ++
  3 files changed, 19 insertions(+), 3 deletions(-)


diff --git a/Lib/http/cookies.py b/Lib/http/cookies.py
--- a/Lib/http/cookies.py
+++ b/Lib/http/cookies.py
@@ -455,12 +455,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<key>                       # 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
@@ -469,7 +470,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 --git a/Lib/test/test_http_cookies.py b/Lib/test/test_http_cookies.py
--- a/Lib/test/test_http_cookies.py
+++ b/Lib/test/test_http_cookies.py
@@ -44,6 +44,19 @@
              'repr': "<SimpleCookie: key:term='value:term'>",
              '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': "<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'
+                ))
+            }
         ]
 
         for case in cases:
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -325,6 +325,8 @@
   lines from the code object, fixing an issue when a lambda function is used as
   decorator argument. Patch by Thomas Ballinger and Allison Kaptur.
 
+- Issue #22931: Allow '[' and ']' in cookie values.
+
 - The keywords attribute of functools.partial is now always a dictionary.
 
 - Issue #23811: Add missing newline to the PyCompileError error message.

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list