From b16e38b8254e0e1bbffaf16971351a5eb31a5846 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Sun, 1 Aug 2010 09:06:34 +0000 Subject: [PATCH] #8826: the "expires" attribute value is a date string with spaces, but apparently not all user-agents put it in quotes. Handle that as a special case. --- Lib/http/cookies.py | 2 ++ Lib/test/test_http_cookies.py | 10 ++++++++++ Misc/NEWS | 2 ++ 3 files changed, 14 insertions(+) diff --git a/Lib/http/cookies.py b/Lib/http/cookies.py index c36c4945799..9e51b6791ca 100644 --- a/Lib/http/cookies.py +++ b/Lib/http/cookies.py @@ -434,6 +434,8 @@ def OutputString(self, attrs=None): (?P # Start of group 'val' "(?:[^\\"]|\\.)*" # Any doublequoted string | # or + \w{3},\s[\w\d-]{9,11}\s[\d:]{8}\sGMT # Special case for "expires" attr + | # or """ + _LegalCharsPatt + r"""* # Any word or empty string ) # End of group 'val' \s*;? # Probably ending in a semi-colon diff --git a/Lib/test/test_http_cookies.py b/Lib/test/test_http_cookies.py index 43ca9f5d62b..b008e0ff2a5 100644 --- a/Lib/test/test_http_cookies.py +++ b/Lib/test/test_http_cookies.py @@ -76,6 +76,16 @@ def test_special_attrs(self): # can't test exact output, it always depends on current date/time self.assertTrue(C.output().endswith('GMT')) + # loading 'expires' + C = cookies.SimpleCookie() + C.load('Customer="W"; expires=Wed, 01-Jan-2010 00:00:00 GMT') + self.assertEqual(C['Customer']['expires'], + 'Wed, 01-Jan-2010 00:00:00 GMT') + C = cookies.SimpleCookie() + C.load('Customer="W"; expires=Wed, 01-Jan-98 00:00:00 GMT') + self.assertEqual(C['Customer']['expires'], + 'Wed, 01-Jan-98 00:00:00 GMT') + # 'max-age' C = cookies.SimpleCookie('Customer="WILE_E_COYOTE"') C['Customer']['max-age'] = 10 diff --git a/Misc/NEWS b/Misc/NEWS index 52cbabd0d95..96ff051abab 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -15,6 +15,8 @@ Core and Builtins Library ------- +- Issue #8826: Properly load old-style "expires" attribute in http.cookies. + - Issue #1690103: Fix initial namespace for code run with trace.main(). - Issue #7395: Fix tracebacks in pstats interactive browser.