[Python-checkins] [3.10] bpo-45239: Fix parsedate_tz when time has more than 2 dots in it (GH-28452) (GH-28930)

ambv webhook-mailer at python.org
Wed Oct 13 13:12:27 EDT 2021


https://github.com/python/cpython/commit/f8473f6f7603f8cccccc3307d4cb853587be41b3
commit: f8473f6f7603f8cccccc3307d4cb853587be41b3
branch: 3.10
author: Łukasz Langa <lukasz at langa.pl>
committer: ambv <lukasz at langa.pl>
date: 2021-10-13T19:12:22+02:00
summary:

[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 <lukasz at langa.pl>
(cherry picked from commit b9e687618d3489944f29adbd2be50b46940c9e70)

Co-authored-by: Ben Hoyt <benhoyt at gmail.com>

files:
A Misc/NEWS.d/next/Library/2021-10-13-17-52-48.bpo-45239.7li1_0.rst
M Lib/email/_parseaddr.py
M Lib/test/test_email/test_email.py

diff --git a/Lib/email/_parseaddr.py b/Lib/email/_parseaddr.py
index 977fedf67b159..ba5ad5a36d06b 100644
--- a/Lib/email/_parseaddr.py
+++ b/Lib/email/_parseaddr.py
@@ -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:
diff --git a/Lib/test/test_email/test_email.py b/Lib/test/test_email/test_email.py
index 4001f716471dc..54ffcdc544e8b 100644
--- a/Lib/test/test_email/test_email.py
+++ b/Lib/test/test_email/test_email.py
@@ -3009,6 +3009,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))
diff --git a/Misc/NEWS.d/next/Library/2021-10-13-17-52-48.bpo-45239.7li1_0.rst b/Misc/NEWS.d/next/Library/2021-10-13-17-52-48.bpo-45239.7li1_0.rst
new file mode 100644
index 0000000000000..9e5ec561c362a
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2021-10-13-17-52-48.bpo-45239.7li1_0.rst
@@ -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.



More information about the Python-checkins mailing list