Skip to content

bpo-45239: Fix parsedate_tz when time has more than 2 dots in it #28452

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Lib/email/_parseaddr.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ def _parsedate_tz(data):
tss = 0
elif len(tm) == 3:
[thh, tmm, tss] = tm
else:
return None
else:
return None
try:
Expand Down
1 change: 1 addition & 0 deletions Lib/test/test_email/test_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -3007,6 +3007,7 @@ def test_parsedate_returns_None_for_invalid_strings(self):
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))
Expand Down
Original file line number Diff line number Diff line change
@@ -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.