Skip to content

Commit 1b78ed1

Browse files
committed
allow double quote in cookie values
1 parent 35fa13d commit 1b78ed1

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
@@ -442,7 +442,7 @@ def OutputString(self, attrs=None):
442442
( # Optional group: there may not be a value.
443443
\s*=\s* # Equal Sign
444444
(?P<val> # Start of group 'val'
445-
"(?:[^\\"]|\\.)*" # Any doublequoted string
445+
"(?:\\"|.)*?" # Any doublequoted string
446446
| # or
447447
\w{3},\s[\w\d\s-]{9,11}\s[\d:]{8}\sGMT # Special case for "expires" attr
448448
| # or

Lib/test/test_http_cookies.py

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

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)