Skip to content

Commit f8473f6

Browse files
ambvbenhoyt
andauthored
[3.10] bpo-45239: Fix parsedate_tz when time has more than 2 dots in it (GH-28452) (GH-28930)
Co-authored-by: Łukasz Langa <[email protected]> (cherry picked from commit b9e6876) Co-authored-by: Ben Hoyt <[email protected]>
1 parent 151234f commit f8473f6

File tree

3 files changed

+6
-0
lines changed

3 files changed

+6
-0
lines changed

Lib/email/_parseaddr.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ def _parsedate_tz(data):
128128
tss = 0
129129
elif len(tm) == 3:
130130
[thh, tmm, tss] = tm
131+
else:
132+
return None
131133
else:
132134
return None
133135
try:

Lib/test/test_email/test_email.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3009,6 +3009,7 @@ def test_parsedate_returns_None_for_invalid_strings(self):
30093009
self.assertIsNone(utils.parsedate_tz('0'))
30103010
self.assertIsNone(utils.parsedate('A Complete Waste of Time'))
30113011
self.assertIsNone(utils.parsedate_tz('A Complete Waste of Time'))
3012+
self.assertIsNone(utils.parsedate_tz('Wed, 3 Apr 2002 12.34.56.78+0800'))
30123013
# Not a part of the spec but, but this has historically worked:
30133014
self.assertIsNone(utils.parsedate(None))
30143015
self.assertIsNone(utils.parsedate_tz(None))
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fixed :func:`email.utils.parsedate_tz` crashing with
2+
:exc:`UnboundLocalError` on certain invalid input instead of returning
3+
``None``. Patch by Ben Hoyt.

0 commit comments

Comments
 (0)