Skip to content

Commit e9b3cd5

Browse files
committed
allow double quote in cookie values
1 parent a4562fe commit e9b3cd5

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
@@ -424,7 +424,7 @@ def OutputString(self, attrs=None):
424424
( # Optional group: there may not be a value.
425425
\s*=\s* # Equal Sign
426426
(?P<val> # Start of group 'val'
427-
"(?:[^\\"]|\\.)*" # Any doublequoted string
427+
"(?:\\"|.)*?" # Any doublequoted string
428428
| # or
429429
\w{3},\s[\w\d\s-]{9,11}\s[\d:]{8}\sGMT # Special case for "expires" attr
430430
| # or

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)