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
This commit is contained in:
Abhilash Raj 2019-08-11 13:45:09 -07:00 committed by Miss Islington (bot)
parent 51aac15f6d
commit 09a1872a80
3 changed files with 12 additions and 1 deletions

View file

@ -1700,6 +1700,14 @@ class TestParser(TestParserMixin, TestEmailBase):
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
# 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):