From 8ba20d9071e9e1b8f2c81d4df977db4278342085 Mon Sep 17 00:00:00 2001 From: Joachim Jablon Date: Thu, 6 Jun 2019 14:47:03 +0200 Subject: [PATCH] Refs #30512 -- Added tests for sanitizing email addresses with display name and two @ signs. --- tests/mail/tests.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tests/mail/tests.py b/tests/mail/tests.py index ed1af26953..0a2db39d64 100644 --- a/tests/mail/tests.py +++ b/tests/mail/tests.py @@ -716,13 +716,38 @@ class MailTests(HeadersCheckMixin, SimpleTestCase): 'utf-8', '=?utf-8?q?A_name?= ', ), + # ASCII addresses with display names. + ('A name ', 'ascii', 'A name '), + ('A name ', 'utf-8', '=?utf-8?q?A_name?= '), + ('"A name" ', 'ascii', 'A name '), + ('"A name" ', 'utf-8', '=?utf-8?q?A_name?= '), # Unicode addresses (supported per RFC-6532). ('tó@example.com', 'utf-8', '=?utf-8?b?dMOz?=@example.com'), + ('to@éxample.com', 'utf-8', 'to@xn--xample-9ua.com'), ( ('Tó Example', 'tó@example.com'), 'utf-8', '=?utf-8?q?T=C3=B3_Example?= <=?utf-8?b?dMOz?=@example.com>', ), + # Unicode addresses with display names. + ( + 'Tó Example ', + 'utf-8', + '=?utf-8?q?T=C3=B3_Example?= <=?utf-8?b?dMOz?=@example.com>', + ), + ('To Example ', 'ascii', 'To Example '), + ( + 'To Example ', + 'utf-8', + '=?utf-8?q?To_Example?= ', + ), + # Addresses with two @ signs. + ('"to@other.com"@example.com', 'utf-8', r'"to@other.com"@example.com'), + ( + '"to@other.com" ', + 'utf-8', + '=?utf-8?q?to=40other=2Ecom?= ', + ), ): with self.subTest(email_address=email_address, encoding=encoding): self.assertEqual(sanitize_address(email_address, encoding), expected_result)