]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-45239: Fix parsedate_tz when time has more than 2 dots in it (GH-28452)
authorBen Hoyt <benhoyt@gmail.com>
Wed, 13 Oct 2021 16:21:27 +0000 (05:21 +1300)
committerGitHub <noreply@github.com>
Wed, 13 Oct 2021 16:21:27 +0000 (18:21 +0200)
Co-authored-by: Ɓukasz Langa <lukasz@langa.pl>
Lib/email/_parseaddr.py
Lib/test/test_email/test_email.py
Misc/NEWS.d/next/Library/2021-10-13-17-52-48.bpo-45239.7li1_0.rst [new file with mode: 0644]

index 977fedf67b1591db4fe2ac532523e4e056bdac3a..ba5ad5a36d06b740d6d515aa7bd47d8464483155 100644 (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:
index 4001f716471dc2431c5ed1ba1bbeeb955e9791fe..54ffcdc544e8bbfcd6d7dd7d41f9676b02cd8ef8 100644 (file)
@@ -3009,6 +3009,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))
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 (file)
index 0000000..9e5ec56
--- /dev/null
@@ -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.