gh-92936: allow double quote in cookie values (#113663)
* allow double quote in cookie values * Update Lib/test/test_http_cookies.py Co-authored-by: Senthil Kumaran <senthil@python.org>
This commit is contained in:
@@ -426,7 +426,7 @@ _CookiePattern = re.compile(r"""
|
|||||||
( # Optional group: there may not be a value.
|
( # Optional group: there may not be a value.
|
||||||
\s*=\s* # Equal Sign
|
\s*=\s* # Equal Sign
|
||||||
(?P<val> # Start of group 'val'
|
(?P<val> # Start of group 'val'
|
||||||
"(?:[^\\"]|\\.)*" # Any double-quoted string
|
"(?:\\"|.)*?" # Any double-quoted string
|
||||||
| # or
|
| # or
|
||||||
# Special case for "expires" attr
|
# Special case for "expires" attr
|
||||||
(\w{3,6}day|\w{3}),\s # Day of the week or abbreviated day
|
(\w{3,6}day|\w{3}),\s # Day of the week or abbreviated day
|
||||||
|
|||||||
@@ -48,6 +48,29 @@ class CookieTests(unittest.TestCase):
|
|||||||
'Set-Cookie: d=r',
|
'Set-Cookie: d=r',
|
||||||
'Set-Cookie: f=h'
|
'Set-Cookie: f=h'
|
||||||
))
|
))
|
||||||
|
},
|
||||||
|
|
||||||
|
# gh-92936: allow double quote in cookie values
|
||||||
|
{
|
||||||
|
'data': 'cookie="{"key": "value"}"',
|
||||||
|
'dict': {'cookie': '{"key": "value"}'},
|
||||||
|
'repr': "<SimpleCookie: cookie='{\"key\": \"value\"}'>",
|
||||||
|
'output': 'Set-Cookie: cookie="{"key": "value"}"',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'data': 'key="some value; surrounded by quotes"',
|
||||||
|
'dict': {'key': 'some value; surrounded by quotes'},
|
||||||
|
'repr': "<SimpleCookie: key='some value; surrounded by quotes'>",
|
||||||
|
'output': 'Set-Cookie: key="some value; surrounded by quotes"',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'data': 'session="user123"; preferences="{"theme": "dark"}"',
|
||||||
|
'dict': {'session': 'user123', 'preferences': '{"theme": "dark"}'},
|
||||||
|
'repr': "<SimpleCookie: preferences='{\"theme\": \"dark\"}' session='user123'>",
|
||||||
|
'output': '\n'.join((
|
||||||
|
'Set-Cookie: preferences="{"theme": "dark"}"',
|
||||||
|
'Set-Cookie: session="user123"',
|
||||||
|
))
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
Update regex used by ``http.cookies.SimpleCookie`` to handle values containing
|
||||||
|
double quotes.
|
||||||
Reference in New Issue
Block a user