Skip to content

Commit 6e3d1d7

Browse files
committed
allow double quote in cookie values
1 parent ee72c95 commit 6e3d1d7

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

Lib/http/cookies.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ def OutputString(self, attrs=None):
426426
( # Optional group: there may not be a value.
427427
\s*=\s* # Equal Sign
428428
(?P<val> # Start of group 'val'
429-
"(?:[^\\"]|\\.)*" # Any double-quoted string
429+
"(?:\\"|.)*?" # Any double-quoted string
430430
| # or
431431
# Special case for "expires" attr
432432
(\w{3,6}day|\w{3}),\s # Day of the week or abbreviated day

Lib/test/test_http_cookies.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,18 @@ def test_basic(self):
4848
'Set-Cookie: d=r',
4949
'Set-Cookie: f=h'
5050
))
51+
},
52+
53+
{'data': 'cookie="{"key": "value"}"',
54+
'dict': {'cookie': '{"key": "value"}'},
55+
'repr': "<SimpleCookie: cookie='{\"key\": \"value\"}'>",
56+
'output': 'Set-Cookie: cookie="{"key": "value"}"',
57+
},
58+
59+
{'data': 'key="some value; surrounded by quotes"',
60+
'dict': {'key': 'some value; surrounded by quotes'},
61+
'repr': "<SimpleCookie: key='some value; surrounded by quotes'>",
62+
'output': 'Set-Cookie: key="some value; surrounded by quotes"',
5163
}
5264
]
5365

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Update regex used by ``http.cookies.SimpleCookie`` to handle values containing
2+
double quotes.

0 commit comments

Comments
 (0)