diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2024-04-17 07:55:11 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-17 07:55:11 (GMT) |
commit | 03108045d25e4a75575d8a19d3187599e17277a4 (patch) | |
tree | ebba209b8171b16306a5fc27b0f773b303e94dce /Lib/test | |
parent | 5f4c7cf3f49629bcf890c305e0a90ffd708110a2 (diff) | |
download | cpython-03108045d25e4a75575d8a19d3187599e17277a4.zip cpython-03108045d25e4a75575d8a19d3187599e17277a4.tar.gz cpython-03108045d25e4a75575d8a19d3187599e17277a4.tar.bz2 |
[3.12] gh-75171: Fix parsing invalid email address headers starting or ending with a dot (GH-15600) (GH-117964)
(cherry picked from commit 8cc9adbfddc8e37cf7d621b12754eecb0584f5da)
Co-authored-by: tsufeki <tsufeki@ymail.com>
Co-authored-by: Tim Bell <timothybell@gmail.com>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_email/test__header_value_parser.py | 26 | ||||
-rw-r--r-- | Lib/test/test_email/test_headerregistry.py | 20 |
2 files changed, 46 insertions, 0 deletions
diff --git a/Lib/test/test_email/test__header_value_parser.py b/Lib/test/test_email/test__header_value_parser.py index f7e8074..dd1af99 100644 --- a/Lib/test/test_email/test__header_value_parser.py +++ b/Lib/test/test_email/test__header_value_parser.py @@ -1805,6 +1805,32 @@ class TestParser(TestParserMixin, TestEmailBase): self.assertIsNone(name_addr.route) self.assertEqual(name_addr.addr_spec, 'dinsdale@example.com') + def test_get_name_addr_ending_with_dot_without_space(self): + name_addr = self._test_get_x(parser.get_name_addr, + 'John X.<jxd@example.com>', + 'John X.<jxd@example.com>', + '"John X."<jxd@example.com>', + [errors.ObsoleteHeaderDefect], + '') + self.assertEqual(name_addr.display_name, 'John X.') + self.assertEqual(name_addr.local_part, 'jxd') + self.assertEqual(name_addr.domain, 'example.com') + self.assertIsNone(name_addr.route) + self.assertEqual(name_addr.addr_spec, 'jxd@example.com') + + def test_get_name_addr_starting_with_dot(self): + name_addr = self._test_get_x(parser.get_name_addr, + '. Doe <jxd@example.com>', + '. Doe <jxd@example.com>', + '". Doe" <jxd@example.com>', + [errors.InvalidHeaderDefect, errors.ObsoleteHeaderDefect], + '') + self.assertEqual(name_addr.display_name, '. Doe') + self.assertEqual(name_addr.local_part, 'jxd') + self.assertEqual(name_addr.domain, 'example.com') + self.assertIsNone(name_addr.route) + self.assertEqual(name_addr.addr_spec, 'jxd@example.com') + def test_get_name_addr_with_route(self): name_addr = self._test_get_x(parser.get_name_addr, '"Roy.A.Bear" <@two.example.com: dinsdale@example.com>', diff --git a/Lib/test/test_email/test_headerregistry.py b/Lib/test/test_email/test_headerregistry.py index 25347ef..bb7ca8d 100644 --- a/Lib/test/test_email/test_headerregistry.py +++ b/Lib/test/test_email/test_headerregistry.py @@ -1237,6 +1237,26 @@ class TestAddressHeader(TestHeaderBase): 'example.com', None), + 'name_ending_with_dot_without_space': + ('John X.<jxd@example.com>', + [errors.ObsoleteHeaderDefect], + '"John X." <jxd@example.com>', + 'John X.', + 'jxd@example.com', + 'jxd', + 'example.com', + None), + + 'name_starting_with_dot': + ('. Doe <jxd@example.com>', + [errors.InvalidHeaderDefect, errors.ObsoleteHeaderDefect], + '". Doe" <jxd@example.com>', + '. Doe', + 'jxd@example.com', + 'jxd', + 'example.com', + None), + } # XXX: Need many more examples, and in particular some with names in |