summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2021-10-13 16:58:37 (GMT)
committerGitHub <noreply@github.com>2021-10-13 16:58:37 (GMT)
commit5638618845752f713c00d69dbe705fed16761948 (patch)
treef29759f26027709d0bb823cc6bd13c1b23a1d24b
parentcc90732d15b267feb4cb75ec4c448a3c66e6c520 (diff)
downloadcpython-5638618845752f713c00d69dbe705fed16761948.zip
cpython-5638618845752f713c00d69dbe705fed16761948.tar.gz
cpython-5638618845752f713c00d69dbe705fed16761948.tar.bz2
bpo-45239: Fix parsedate_tz when time has more than 2 dots in it (GH-28452) (GH-28928)
Co-authored-by: Ɓukasz Langa <lukasz@langa.pl> (cherry picked from commit b9e687618d3489944f29adbd2be50b46940c9e70) Co-authored-by: Ben Hoyt <benhoyt@gmail.com>
-rw-r--r--Lib/email/_parseaddr.py2
-rw-r--r--Lib/test/test_email/test_email.py1
-rw-r--r--Misc/NEWS.d/next/Library/2021-10-13-17-52-48.bpo-45239.7li1_0.rst3
3 files changed, 6 insertions, 0 deletions
diff --git a/Lib/email/_parseaddr.py b/Lib/email/_parseaddr.py
index 178329f..c5a7b23 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 217a5b8..bc062b5 100644
--- a/Lib/test/test_email/test_email.py
+++ b/Lib/test/test_email/test_email.py
@@ -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
index 0000000..9e5ec56
--- /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.