Ticket #28690: parse-http-date-year.patch
File parse-http-date-year.patch, 2.1 KB (added by , 7 years ago) |
---|
-
django/utils/http.py
diff --git a/django/utils/http.py b/django/utils/http.py index c13f446..8008714 100644
a b def parse_http_date(date): 132 132 133 133 Return an integer expressed in seconds since the epoch, in UTC. 134 134 """ 135 # email s.Util.parsedate does the job for RFC1123 dates; unfortunately135 # email.utils.parsedate does the job for RFC1123 dates; unfortunately 136 136 # RFC7231 makes it mandatory to support RFC850 dates too. So we roll 137 137 # our own RFC-compliant parsing. 138 138 for regex in RFC1123_DATE, RFC850_DATE, ASCTIME_DATE: … … def parse_http_date(date): 144 144 try: 145 145 year = int(m.group('year')) 146 146 if year < 100: 147 if year < 70:147 if year < 50: 148 148 year += 2000 149 149 else: 150 150 year += 1900 -
tests/utils_tests/test_http.py
diff --git a/tests/utils_tests/test_http.py b/tests/utils_tests/test_http.py index 04c2d55..0df0967 100644
a b class HttpDateProcessingTests(unittest.TestCase): 223 223 parsed = http.parse_http_date('Sunday, 06-Nov-94 08:49:37 GMT') 224 224 self.assertEqual(datetime.utcfromtimestamp(parsed), datetime(1994, 11, 6, 8, 49, 37)) 225 225 226 def test_parsing_rfc850_year(self): 227 dates = ( 228 ('Monday, 15-Aug-05 08:49:37 GMT', datetime(2005, 8, 15, 8, 49, 37)), 229 ('Monday, 15-Aug-55 08:49:37 GMT', datetime(1955, 8, 15, 8, 49, 37)), 230 ('Monday, 15-Aug-49 08:49:37 GMT', datetime(2049, 8, 15, 8, 49, 37)), 231 ('Monday, 15-Aug-95 08:49:37 GMT', datetime(1995, 8, 15, 8, 49, 37)), 232 ) 233 for rfc850str, rfc850date in dates: 234 with self.subTest(string=rfc850str, date=rfc850date): 235 parsed = http.parse_http_date(rfc850str) 236 self.assertEqual( 237 datetime.utcfromtimestamp(parsed), 238 rfc850date 239 ) 240 226 241 def test_parsing_asctime(self): 227 242 parsed = http.parse_http_date('Sun Nov 6 08:49:37 1994') 228 243 self.assertEqual(datetime.utcfromtimestamp(parsed), datetime(1994, 11, 6, 8, 49, 37))