Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
9bd476ea
Commit
9bd476ea
authored
May 23, 2015
by
Benjamin Peterson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
allow square brackets in cookie values (closes #22931)
parent
0823ffb2
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
3 deletions
+23
-3
Lib/http/cookies.py
Lib/http/cookies.py
+4
-3
Lib/test/test_http_cookies.py
Lib/test/test_http_cookies.py
+14
-0
Misc/NEWS
Misc/NEWS
+5
-0
No files found.
Lib/http/cookies.py
View file @
9bd476ea
...
...
@@ -429,12 +429,13 @@ class Morsel(dict):
# 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* # Op
tional 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'
\
s*=
\s* # Equal Sign
(?P<val> # Start of group 'val'
...
...
@@ -442,7 +443,7 @@ _CookiePattern = re.compile(r"""
|
# 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'
\
s
*
;
?
# Probably ending in a semi-colon
""", re.ASCII) # May be removed if safe.
...
...
Lib/test/test_http_cookies.py
View file @
9bd476ea
...
...
@@ -34,6 +34,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'
))
}
]
for
case
in
cases
:
...
...
Misc/NEWS
View file @
9bd476ea
...
...
@@ -16,6 +16,11 @@ Core and Builtins
- Issue #23055: Fixed a buffer overflow in PyUnicode_FromFormatV. Analysis
and fix by Guido Vranken.
Library
-------
- Issue #22931: Allow '[' and ']' in cookie values.
What's New in Python 3.2.6?
===========================
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment