]> 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) (GH-28928)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Wed, 13 Oct 2021 16:58:37 +0000 (09:58 -0700)
committerGitHub <noreply@github.com>
Wed, 13 Oct 2021 16:58:37 +0000 (18:58 +0200)
Co-authored-by: Ɓukasz Langa <lukasz@langa.pl>
(cherry picked from commit b9e687618d3489944f29adbd2be50b46940c9e70)

Co-authored-by: Ben Hoyt <benhoyt@gmail.com>
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 178329fbc6aacd92c18f7a6891674d4ef7a482ad..c5a7b23193ef4d8f7a380b373dce6c8a81593a88 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 217a5b871090960db0e08f493556814cfffb94a2..bc062b5cb0c5910ce1fe9676644ea6418346cd32 100644 (file)
@@ -3008,6 +3008,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.