8000 pythongh-123401: Fix http.cookies module to support obsolete RFC 850 … · Konano/cpython@db912d8 · GitHub
[go: up one dir, main page]

Skip to content

Commit db912d8

Browse files
committed
pythongh-123401: Fix http.cookies module to support obsolete RFC 850 date format
1 parent d24d1c9 commit db912d8

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

Lib/http/cookies.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,9 @@ def OutputString(self, attrs=None):
426426
(?P<val> # Start of group 'val'
427427
"(?:[^\\"]|\\.)*" # Any doublequoted string
428428
| # or
429-
\w{3},\s[\w\d\s-]{9,11}\s[\d:]{8}\sGMT # Special case for "expires" attr
429+
# Special case for "expires" attr
430+
(\w{3,6}day|\w{3}),\s # Day of the week or abbreviated day
431+
[\w\d\s-]{9,11}\s[\d:]{8}\sGMT # Date and time in specific format
430432
| # or
431433
[""" + _LegalValueChars + r"""]* # Any word or empty string
432434
) # End of group 'val'

Lib/test/test_http_cookies.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,39 @@ def test_basic(self):
5959
for k, v in sorted(case['dict'].items()):
6060
self.assertEqual(C[k].value, v)
6161

62+
def test_obsolete_rfc850_date_format(self):
63+
# Test cases with different days and dates in obsolete RFC 850 format
64+
test_cases = [
65+
{
66+
'data': 'key=value; expires=Sunday, 06-Nov-94 08:49:37 GMT',
67+
'output': 'Sunday, 06-Nov-94 08:49:37 GMT'
68+
},
69+
{
70+
'data': 'key=value; expires=Wednesday, 09-Nov-94 08:49:37 GMT',
71+
'output': 'Wednesday, 09-Nov-94 08:49:37 GMT'
72+
},
73+
{
74+
'data': 'key=value; expires=Friday, 11-Nov-94 08:49:37 GMT',
75+
'output': 'Friday, 11-Nov-94 08:49:37 GMT'
76+
},
77+
{
78+
'data': 'key=value; expires=Monday, 14-Nov-94 08:49:37 GMT',
79+
'output': 'Monday, 14-Nov-94 08:49:37 GMT'
80+
},
81+
]
82+
83+
for case in test_cases:
84+
with self.subTest(data=case['data']):
85+
C = cookies.SimpleCookie()
86+
C.load(case['data'])
87+
88+
# Extract the cookie name from the data string
89+
cookie_name = case['data'].split('=')[0]
90+
91+
# Check if the cookie is loaded correctly
92+
self.assertIn(cookie_name, C)
93+
self.assertEqual(C[cookie_name].get('expires'), case['output'])
94+
6295
def test_unquote(self):
6396
cases = [
6497
(r'a="b=\""', 'b="'),

0 commit comments

Comments
 (0)
0