summaryrefslogtreecommitdiffstats
path: root/Lib/email
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2019-08-11 21:04:31 (GMT)
committerGitHub <noreply@github.com>2019-08-11 21:04:31 (GMT)
commit9500bbe9372f6080decc49d2fd9365f0b927a0e2 (patch)
treeccc4bc441185a56739a190c80588ac43abda052e /Lib/email
parentc61f9b57cfce9e96bdea5674634e3a9c185b675f (diff)
downloadcpython-9500bbe9372f6080decc49d2fd9365f0b927a0e2.zip
cpython-9500bbe9372f6080decc49d2fd9365f0b927a0e2.tar.gz
cpython-9500bbe9372f6080decc49d2fd9365f0b927a0e2.tar.bz2
bpo-32178: Fix IndexError trying to parse 'To' header starting with ':'. (GH-15044)
This should fix the IndexError trying to retrieve `DisplayName.display_name` and `DisplayName.value` when the `value` is basically an empty string. https://bugs.python.org/issue32178 (cherry picked from commit 09a1872a8007048dcdf825a476816c5e3498b8f8) Co-authored-by: Abhilash Raj <maxking@users.noreply.github.com>
Diffstat (limited to 'Lib/email')
-rw-r--r--Lib/email/_header_value_parser.py4
1 files changed, 3 insertions, 1 deletions
diff --git a/Lib/email/_header_value_parser.py b/Lib/email/_header_value_parser.py
index a930792..3d369e4 100644
--- a/Lib/email/_header_value_parser.py
+++ b/Lib/email/_header_value_parser.py
@@ -549,6 +549,8 @@ class DisplayName(Phrase):
@property
def display_name(self):
res = TokenList(self)
+ if len(res) == 0:
+ return res.value
if res[0].token_type == 'cfws':
res.pop(0)
else:
@@ -570,7 +572,7 @@ class DisplayName(Phrase):
for x in self:
if x.token_type == 'quoted-string':
quote = True
- if quote:
+ if len(self) != 0 and quote:
pre = post = ''
if self[0].token_type=='cfws' or self[0][0].token_type=='cfws':
pre = ' '