Skip to content

Commit

Permalink
Fix failing test by catching year overflow ValueError
Browse files Browse the repository at this point in the history
  • Loading branch information
alanhamlett committed Mar 9, 2022
1 parent 93db7ce commit 0f6c839
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
8 changes: 8 additions & 0 deletions CHANGES.rst
@@ -1,3 +1,11 @@
Version 2.1.1
-------------

Unreleased

- Handle date overflow in timed unsign. :pr:`296`


Version 2.1.0
-------------

Expand Down
2 changes: 1 addition & 1 deletion src/itsdangerous/__init__.py
Expand Up @@ -16,4 +16,4 @@
from .url_safe import URLSafeSerializer as URLSafeSerializer
from .url_safe import URLSafeTimedSerializer as URLSafeTimedSerializer

__version__ = "2.1.0"
__version__ = "2.1.1.dev0"
10 changes: 8 additions & 2 deletions src/itsdangerous/timed.py
Expand Up @@ -38,7 +38,8 @@ def get_timestamp(self) -> int:

def timestamp_to_datetime(self, ts: int) -> datetime:
"""Convert the timestamp from :meth:`get_timestamp` into an
aware :class`datetime.datetime` in UTC.
aware :class`datetime.datetime` in UTC. Raises :exc:`.ValueError`
if the timestamp is too far in the past or future for Python.
.. versionchanged:: 2.0
The timestamp is returned as a timezone-aware ``datetime``
Expand Down Expand Up @@ -124,7 +125,12 @@ def unsign(
# split the value and the timestamp.
if sig_error is not None:
if ts_int is not None:
ts_dt = self.timestamp_to_datetime(ts_int)
try:
ts_dt = self.timestamp_to_datetime(ts_int)
except ValueError as exc:
raise BadTimeSignature(
"Malformed timestamp", payload=value
) from exc

raise BadTimeSignature(str(sig_error), payload=value, date_signed=ts_dt)

Expand Down

0 comments on commit 0f6c839

Please sign in to comment.