diff options
author | 2018-07-28 08:59:18 -0700 | |
---|---|---|
committer | 2018-07-28 08:59:18 -0700 | |
commit | f17e001746e0f697e9bd49ac3748f2543b0a0d47 (patch) | |
tree | 9f1385b48c61b1310209b4d7e207ebad9437c54d /Lib | |
parent | bpo-33921: Clarify how to bind to all interfaces using socket (GH-7877) (diff) | |
download | cpython-f17e001746e0f697e9bd49ac3748f2543b0a0d47.tar.gz cpython-f17e001746e0f697e9bd49ac3748f2543b0a0d47.tar.bz2 cpython-f17e001746e0f697e9bd49ac3748f2543b0a0d47.zip |
bpo-33476: Fix _header_value_parser when address group is missing final ';' (GH-7484)
(cherry picked from commit 8fe9eed937cb69b5e26ac6e36a90b5360eb11277)
Co-authored-by: Dong-hee Na <donghee.na92@gmail.com>
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/email/_header_value_parser.py | 2 | ||||
-rw-r--r-- | Lib/test/test_email/test__header_value_parser.py | 25 |
2 files changed, 26 insertions, 1 deletions
diff --git a/Lib/email/_header_value_parser.py b/Lib/email/_header_value_parser.py index 14ffd30ca47..de7ab5d12e7 100644 --- a/Lib/email/_header_value_parser.py +++ b/Lib/email/_header_value_parser.py @@ -1876,7 +1876,7 @@ def get_group(value): if not value: group.defects.append(errors.InvalidHeaderDefect( "end of header in group")) - if value[0] != ';': + elif value[0] != ';': raise errors.HeaderParseError( "expected ';' at end of group but found {}".format(value)) group.append(ValueTerminal(';', 'group-terminator')) diff --git a/Lib/test/test_email/test__header_value_parser.py b/Lib/test/test_email/test__header_value_parser.py index 5036de2ca0c..676732bb3d0 100644 --- a/Lib/test/test_email/test__header_value_parser.py +++ b/Lib/test/test_email/test__header_value_parser.py @@ -2152,6 +2152,31 @@ class TestParser(TestParserMixin, TestEmailBase): self.assertEqual(group.mailboxes[1].local_part, 'x') self.assertIsNone(group.all_mailboxes[1].display_name) + def test_get_group_missing_final_semicol(self): + group = self._test_get_x(parser.get_group, + ('Monty Python:"Fred A. Bear" <dinsdale@example.com>,' + 'eric@where.test,John <jdoe@test>'), + ('Monty Python:"Fred A. Bear" <dinsdale@example.com>,' + 'eric@where.test,John <jdoe@test>;'), + ('Monty Python:"Fred A. Bear" <dinsdale@example.com>,' + 'eric@where.test,John <jdoe@test>;'), + [errors.InvalidHeaderDefect], + '') + self.assertEqual(group.token_type, 'group') + self.assertEqual(group.display_name, 'Monty Python') + self.assertEqual(len(group.mailboxes), 3) + self.assertEqual(group.mailboxes, + group.all_mailboxes) + self.assertEqual(group.mailboxes[0].addr_spec, + 'dinsdale@example.com') + self.assertEqual(group.mailboxes[0].display_name, + 'Fred A. Bear') + self.assertEqual(group.mailboxes[1].addr_spec, + 'eric@where.test') + self.assertEqual(group.mailboxes[2].display_name, + 'John') + self.assertEqual(group.mailboxes[2].addr_spec, + 'jdoe@test') # get_address def test_get_address_simple(self): |