Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-32178: Fix IndexError trying to parse 'To' header starting with ':'. #15044

Merged
merged 4 commits into from
Aug 11, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Lib/email/_header_value_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,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:
Expand All @@ -582,7 +584,7 @@ def value(self):
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 = ' '
Expand Down
8 changes: 8 additions & 0 deletions Lib/test/test_email/test__header_value_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1700,6 +1700,14 @@ def test_get_display_name_ending_with_obsolete(self):
self.assertEqual(display_name[3].comments, ['with trailing comment'])
self.assertEqual(display_name.display_name, 'simple phrase.')

def test_get_display_name_for_invalid_address_field(self):
# bpo-32178: Test that address fields starting with `:` don't cause
maxking marked this conversation as resolved.
Show resolved Hide resolved
# IndexError when parsing the display name.
display_name = self._test_get_x(
parser.get_display_name,
':Foo ', '', '', [errors.InvalidHeaderDefect], ':Foo ')
self.assertEqual(display_name.value, '')

# get_name_addr

def test_get_name_addr_angle_addr_only(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix IndexError trying to parse invalid address fields starting with ``:``.
maxking marked this conversation as resolved.
Show resolved Hide resolved