diff options
| author | Ad Timmering <awtimmering@gmail.com> | 2019-09-28 13:15:38 +0900 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2019-09-30 15:39:36 +0200 |
| commit | 556d0c08bded4cdeaedd513c4c73dbf05fd8650e (patch) | |
| tree | ed051f70c4b08baef5bac06f229b4d6f318de31f /django | |
| parent | f38655ed1c701ebbaffab15cc6ae56376b9c25ba (diff) | |
[3.0.x] Fixed #28690 -- Fixed handling of two-digit years in parse_http_date().
Due to RFC7231 ayear that appears to be more than 50 years in the
future are interpreted as representing the past.
Backport of 7b5f8acb9e6395a1660dd7bfeb365866ca8ef47c from master
Diffstat (limited to 'django')
| -rw-r--r-- | django/utils/http.py | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/django/utils/http.py b/django/utils/http.py index 572cfb4347..ff2f08ac1e 100644 --- a/django/utils/http.py +++ b/django/utils/http.py @@ -176,10 +176,14 @@ def parse_http_date(date): try: year = int(m.group('year')) if year < 100: - if year < 70: - year += 2000 + current_year = datetime.datetime.utcnow().year + current_century = current_year - (current_year % 100) + if year - (current_year % 100) > 50: + # year that appears to be more than 50 years in the future are + # interpreted as representing the past. + year += current_century - 100 else: - year += 1900 + year += current_century month = MONTHS.index(m.group('mon').lower()) + 1 day = int(m.group('day')) hour = int(m.group('hour')) |
