bpo-45239: Fix parsedate_tz when time has more than 2 dots in it (GH-28452) (GH-28928)

Co-authored-by: Łukasz Langa <lukasz@langa.pl>
(cherry picked from commit b9e687618d)

Co-authored-by: Ben Hoyt <benhoyt@gmail.com>
This commit is contained in:
Miss Islington (bot) 2021-10-13 09:58:37 -07:00 committed by GitHub
parent cc90732d15
commit 5638618845
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 0 deletions

View file

@ -128,6 +128,8 @@ def _parsedate_tz(data):
tss = 0
elif len(tm) == 3:
[thh, tmm, tss] = tm
else:
return None
else:
return None
try:

View file

@ -3008,6 +3008,7 @@ class TestMiscellaneous(TestEmailBase):
self.assertIsNone(utils.parsedate_tz('0'))
self.assertIsNone(utils.parsedate('A Complete Waste of Time'))
self.assertIsNone(utils.parsedate_tz('A Complete Waste of Time'))
self.assertIsNone(utils.parsedate_tz('Wed, 3 Apr 2002 12.34.56.78+0800'))
# Not a part of the spec but, but this has historically worked:
self.assertIsNone(utils.parsedate(None))
self.assertIsNone(utils.parsedate_tz(None))

View file

@ -0,0 +1,3 @@
Fixed :func:`email.utils.parsedate_tz` crashing with
:exc:`UnboundLocalError` on certain invalid input instead of returning
``None``. Patch by Ben Hoyt.