[Python-checkins] bpo-33476: Fix _header_value_parser when address group is missing final '; ' (GH-7484)

Miss Islington (bot) webhook-mailer at python.org
Sat Jul 28 11:41:29 EDT 2018


https://github.com/python/cpython/commit/2be0124b820729eacc1288950b824e336bd3a4a6
commit: 2be0124b820729eacc1288950b824e336bd3a4a6
branch: 3.7
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2018-07-28T08:41:26-07:00
summary:

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 at gmail.com>

files:
A Misc/NEWS.d/next/Library/2018-06-08-00-29-40.bpo-33476.R0Bhlj.rst
M Lib/email/_header_value_parser.py
M Lib/test/test_email/test__header_value_parser.py

diff --git a/Lib/email/_header_value_parser.py b/Lib/email/_header_value_parser.py
index d8becee19892..e805a75fbd93 100644
--- a/Lib/email/_header_value_parser.py
+++ b/Lib/email/_header_value_parser.py
@@ -1875,7 +1875,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 5036de2ca0c3..676732bb3d02 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 @@ def test_get_group_one_invalid(self):
         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 at example.com>,'
+             'eric at where.test,John <jdoe at test>'),
+            ('Monty Python:"Fred A. Bear" <dinsdale at example.com>,'
+             'eric at where.test,John <jdoe at test>;'),
+            ('Monty Python:"Fred A. Bear" <dinsdale at example.com>,'
+             'eric at where.test,John <jdoe at 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 at example.com')
+        self.assertEqual(group.mailboxes[0].display_name,
+                         'Fred A. Bear')
+        self.assertEqual(group.mailboxes[1].addr_spec,
+                         'eric at where.test')
+        self.assertEqual(group.mailboxes[2].display_name,
+                         'John')
+        self.assertEqual(group.mailboxes[2].addr_spec,
+                         'jdoe at test')
     # get_address
 
     def test_get_address_simple(self):
diff --git a/Misc/NEWS.d/next/Library/2018-06-08-00-29-40.bpo-33476.R0Bhlj.rst b/Misc/NEWS.d/next/Library/2018-06-08-00-29-40.bpo-33476.R0Bhlj.rst
new file mode 100644
index 000000000000..8104753c055e
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2018-06-08-00-29-40.bpo-33476.R0Bhlj.rst
@@ -0,0 +1,2 @@
+Fix _header_value_parser.py when address group is missing final ';'.
+Contributed by Enrique Perez-Terron



More information about the Python-checkins mailing list