diff --git a/Lib/test/test_email/test_email.py b/Lib/test/test_email/test_email.py index 56a80631c97f18..0e3f6d1dfec4eb 100644 --- a/Lib/test/test_email/test_email.py +++ b/Lib/test/test_email/test_email.py @@ -3319,6 +3319,23 @@ def test_parsing_errors(self): # Test email.utils.supports_strict_parsing attribute self.assertEqual(email.utils.supports_strict_parsing, True) + def test_parseaddr_unicode(self): + # CVE-2023-27043 Unicode regression guard. The 2.7 refactor had to + # accept both str and unicode at the parseaddr() boundary; in Python 3 + # str is already Unicode, so this test just pins that strict-mode + # parsing still accepts valid non-ASCII input and agrees with the + # non-strict path. + for addr in ( + 'user@example.com', + 'Test User ', + '"Test User" ', + '"Sürname, Firstname" ', + ): + with self.subTest(addr=addr): + strict = utils.parseaddr(addr, strict=True) + self.assertNotEqual(strict, ('', '')) + self.assertEqual(strict, utils.parseaddr(addr, strict=False)) + def test_getaddresses_nasty(self): for addresses, expected in ( (['"Sürname, Firstname" '],