Philipp Hörist pushed to branch master at gajim / python-nbxmpp
Commits:
6e6ffb7b by Philipp Hörist at 2023-11-25T12:41:37+01:00
fix: DateTime: Be more strict with parsing
Don’t parse timestamps which may fail conversion to different timezones
- - - - -
2 changed files:
- nbxmpp/modules/date_and_time.py
- test/unit/test_datetime_parsing.py
Changes:
=====================================
nbxmpp/modules/date_and_time.py
=====================================
@@ -160,6 +160,11 @@ def parse_datetime(
except ValueError:
return None
+ if not 1 < date_time.year < 9999:
+ # Raise/Reduce MIN/MAX year so converting to different
+ # timezones cannot get out of range
+ return None
+
if check_utc:
if convert != 'utc':
raise ValueError(
=====================================
test/unit/test_datetime_parsing.py
=====================================
@@ -37,6 +37,10 @@ class TestDateTime(unittest.TestCase):
'2017-11-05T07:41:20+05:00': datetime(2017, 11, 5, 2, 41, 20, 0,
timezone.utc),
'2017-11-05T01:41:20+00:00': datetime(2017, 11, 5, 1, 41, 20, 0,
timezone.utc),
'2017-11-05T01:41:20Z': datetime(2017, 11, 5, 1, 41, 20, 0,
timezone.utc),
+ '0002-11-05T01:41:20Z': datetime(2, 11, 5, 1, 41, 20, 0,
timezone.utc),
+ '9998-11-05T01:41:20Z': datetime(9998, 11, 5, 1, 41, 20, 0,
timezone.utc),
+ '0001-11-05T01:41:20Z': None,
+ '9999-11-05T01:41:20Z': None,
}
for time_string, expected_value in strings.items():
View it on GitLab:
https://dev.gajim.org/gajim/python-nbxmpp/-/commit/6e6ffb7b2427cae8d1200008ad0542cce81db29c
--
View it on GitLab:
https://dev.gajim.org/gajim/python-nbxmpp/-/commit/6e6ffb7b2427cae8d1200008ad0542cce81db29c
You're receiving this email because of your account on dev.gajim.org.
_______________________________________________
Commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]