Skip to content

Commit

Permalink
zfill year < 1000
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolary authored and davidism committed Mar 17, 2020
1 parent 8568bed commit b70df18
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Expand Up @@ -10,6 +10,8 @@ Unreleased
- Only allow a single access control allow origin value. :pr:`1723`
- Fix crash when trying to parse a non-existent Content Security
Policy header. :pr:`1731`
- ``http_date`` zero fills years < 1000 to always output four digits.
:issue:`1739`


Version 1.0.0
Expand Down
4 changes: 2 additions & 2 deletions src/werkzeug/http.py
Expand Up @@ -865,7 +865,7 @@ def _dump_date(d, delim):
d = d.utctimetuple()
elif isinstance(d, (integer_types, float)):
d = gmtime(d)
return "%s, %02d%s%s%s%s %02d:%02d:%02d GMT" % (
return "%s, %02d%s%s%s%04d %02d:%02d:%02d GMT" % (
("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun")[d.tm_wday],
d.tm_mday,
delim,
Expand All @@ -884,7 +884,7 @@ def _dump_date(d, delim):
"Dec",
)[d.tm_mon - 1],
delim,
str(d.tm_year),
d.tm_year,
d.tm_hour,
d.tm_min,
d.tm_sec,
Expand Down
12 changes: 12 additions & 0 deletions tests/test_http.py
Expand Up @@ -668,6 +668,18 @@ def test_content_range_parsing(self):
assert rv.length == 100
assert rv.units == "bytes"

@pytest.mark.parametrize(
("args", "expected"),
(
((1, 1, 1), "Mon, 01 Jan 0001 00:00:00 GMT"),
((999, 1, 1), "Tue, 01 Jan 0999 00:00:00 GMT"),
((1000, 1, 1), "Wed, 01 Jan 1000 00:00:00 GMT"),
((2020, 1, 1), "Wed, 01 Jan 2020 00:00:00 GMT"),
),
)
def test_http_date_lt_1000(self, args, expected):
assert http.http_date(datetime(*args)) == expected


class TestRegression(object):
def test_best_match_works(self):
Expand Down

0 comments on commit b70df18

Please sign in to comment.