From 2628ea95151feb68f43a2a740e6fb0799a94b14b Mon Sep 17 00:00:00 2001 From: Joachim Jablon Date: Mon, 29 Apr 2019 18:48:20 +0200 Subject: Fixed #30512 -- Used email.headerregistry.parser for parsing emails in sanitize_address(). --- tests/mail/tests.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'tests') diff --git a/tests/mail/tests.py b/tests/mail/tests.py index 0a2db39d64..aed4b89928 100644 --- a/tests/mail/tests.py +++ b/tests/mail/tests.py @@ -748,10 +748,30 @@ class MailTests(HeadersCheckMixin, SimpleTestCase): 'utf-8', '=?utf-8?q?to=40other=2Ecom?= ', ), + ( + ('To Example', 'to@other.com@example.com'), + 'utf-8', + '=?utf-8?q?To_Example?= <"to@other.com"@example.com>', + ), ): with self.subTest(email_address=email_address, encoding=encoding): self.assertEqual(sanitize_address(email_address, encoding), expected_result) + def test_sanitize_address_invalid(self): + for email_address in ( + # Invalid address with two @ signs. + 'to@other.com@example.com', + # Invalid address without the quotes. + 'to@other.com ', + # Other invalid addresses. + '@', + 'to@', + '@example.com', + ): + with self.subTest(email_address=email_address): + with self.assertRaises(ValueError): + sanitize_address(email_address, encoding='utf-8') + @requires_tz_support class MailTimeZoneTests(SimpleTestCase): -- cgit v1.3