| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent bcdd10d commit a94e20e
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -424,9 +424,11 @@ def OutputString(self, attrs=None): | |||
| 424 | 424 | ( # Optional group: there may not be a value. | |
| 425 | 425 | \s*=\s* # Equal Sign | |
| 426 | 426 | (?P<val> # Start of group 'val' | |
| 427 | - "(?:[^\\"]|\\.)*" # Any doublequoted string | ||
| 427 | + "(?:[^\\"]|\\.)*" # Any double-quoted string | ||
| 428 | 428 | | # 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 | ||
| 430 | 432 | | # or | |
| 431 | 433 | [""" + _LegalValueChars + r"""]* # Any word or empty string | |
| 432 | 434 | ) # End of group 'val' | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -59,6 +59,52 @@ def test_basic(self): | |||
| 59 | 59 | for k, v in sorted(case['dict'].items()): | |
| 60 | 60 | self.assertEqual(C[k].value, v) | |
| 61 | 61 | ||
| 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 | + # from RFC 850, change EST to GMT | ||
| 66 | + # https://datatracker.ietf.org/doc/html/rfc850#section-2 | ||
| 67 | + { | ||
| 68 | + 'data': 'key=value; expires=Saturday, 01-Jan-83 00:00:00 GMT', | ||
| 69 | + 'output': 'Saturday, 01-Jan-83 00:00:00 GMT' | ||
| 70 | + }, | ||
| 71 | + { | ||
| 72 | + 'data': 'key=value; expires=Friday, 19-Nov-82 16:59:30 GMT', | ||
| 73 | + 'output': 'Friday, 19-Nov-82 16:59:30 GMT' | ||
| 74 | + }, | ||
| 75 | + # from RFC 9110 | ||
| 76 | + # https://www.rfc-editor.org/rfc/rfc9110.html#section-5.6.7-6 | ||
| 77 | + { | ||
| 78 | + 'data': 'key=value; expires=Sunday, 06-Nov-94 08:49:37 GMT', | ||
| 79 | + 'output': 'Sunday, 06-Nov-94 08:49:37 GMT' | ||
| 80 | + }, | ||
| 81 | + # other test cases | ||
| 82 | + { | ||
| 83 | + 'data': 'key=value; expires=Wednesday, 09-Nov-94 08:49:37 GMT', | ||
| 84 | + 'output': 'Wednesday, 09-Nov-94 08:49:37 GMT' | ||
| 85 | + }, | ||
| 86 | + { | ||
| 87 | + 'data': 'key=value; expires=Friday, 11-Nov-94 08:49:37 GMT', | ||
| 88 | + 'output': 'Friday, 11-Nov-94 08:49:37 GMT' | ||
| 89 | + }, | ||
| 90 | + { | ||
| 91 | + 'data': 'key=value; expires=Monday, 14-Nov-94 08:49:37 GMT', | ||
| 92 | + 'output': 'Monday, 14-Nov-94 08:49:37 GMT' | ||
| 93 | + }, | ||
| 94 | + ] | ||
| 95 | + | ||
| 96 | + for case in test_cases: | ||
| 97 | + with self.subTest(data=case['data']): | ||
| 98 | + C = cookies.SimpleCookie() | ||
| 99 | + C.load(case['data']) | ||
| 100 | + | ||
| 101 | + # Extract the cookie name from the data string | ||
| 102 | + cookie_name = case['data'].split('=')[0] | ||
| 103 | + | ||
| 104 | + # Check if the cookie is loaded correctly | ||
| 105 | + self.assertIn(cookie_name, C) | ||
| 106 | + self.assertEqual(C[cookie_name].get('expires'), case['output']) | ||
| 107 | + | ||
| 62 | 108 | def test_unquote(self): | |
| 63 | 109 | cases = [ | |
| 64 | 110 | (r'a="b=\""', 'b="'), | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,3 @@ | |||
| 1 | + The :mod:`http.cookies` module now supports parsing obsolete :rfc:`850` | ||
| 2 | + date formats, in accordance with :rfc:`9110` requirements. | ||
| 3 | + Patch by Nano Zheng. | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments