gh-95087: Fix IndexError in parsing invalid date in the email module (GH-95201)

Co-authored-by: wouter bolsterlee <wouter@bolsterl.ee>
This commit is contained in:
Serhiy Storchaka 2022-07-25 09:17:25 +03:00 committed by GitHub
parent 5956de16cd
commit ea5ed0ba51
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 60 additions and 23 deletions

View file

@ -95,6 +95,8 @@ def _parsedate_tz(data):
return None
data = data[:5]
[dd, mm, yy, tm, tz] = data
if not (dd and mm and yy):
return None
mm = mm.lower()
if mm not in _monthnames:
dd, mm = mm, dd.lower()
@ -110,6 +112,8 @@ def _parsedate_tz(data):
yy, tm = tm, yy
if yy[-1] == ',':
yy = yy[:-1]
if not yy:
return None
if not yy[0].isdigit():
yy, tz = tz, yy
if tm[-1] == ',':