Skip to content

Commit ee122d3

Browse files
committed
gh-95087: make email date parsing more robust
Similar to bpo-45001 (GH-89164), this makes email date parsing more robust against malformed input. parsedate_tz() is supposed to return None for malformed input, but could crash on certain inputs, e.g. >>> email.utils.parsedate_tz('17 June , 2022') IndexError: string index out of range Fixes gh-95087.
1 parent e402b26 commit ee122d3

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

Lib/email/_parseaddr.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def _parsedate_tz(data):
110110
yy, tm = tm, yy
111111
if yy[-1] == ',':
112112
yy = yy[:-1]
113-
if not yy[0].isdigit():
113+
if yy and not yy[0].isdigit():
114114
yy, tz = tz, yy
115115
if tm[-1] == ',':
116116
tm = tm[:-1]

Lib/test/test_email/test_email.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3053,6 +3053,7 @@ def test_parsedate_returns_None_for_invalid_strings(self):
30533053
self.assertIsNone(utils.parsedate_tz(' '))
30543054
self.assertIsNone(utils.parsedate('0'))
30553055
self.assertIsNone(utils.parsedate_tz('0'))
3056+
self.assertIsNone(utils.parsedate_tz('17 June , 2022'))
30563057
self.assertIsNone(utils.parsedate('A Complete Waste of Time'))
30573058
self.assertIsNone(utils.parsedate_tz('A Complete Waste of Time'))
30583059
self.assertIsNone(utils.parsedate_tz('Wed, 3 Apr 2002 12.34.56.78+0800'))

0 commit comments

Comments
 (0)