Refs #30512 -- Added tests for sanitizing email addresses with display name and two @ signs.

This commit is contained in:
Joachim Jablon 2019-06-06 14:47:03 +02:00 committed by Mariusz Felisiak
parent f841a776fe
commit 8ba20d9071
1 changed files with 25 additions and 0 deletions

View File

@ -716,13 +716,38 @@ class MailTests(HeadersCheckMixin, SimpleTestCase):
'utf-8', 'utf-8',
'=?utf-8?q?A_name?= <to@example.com>', '=?utf-8?q?A_name?= <to@example.com>',
), ),
# ASCII addresses with display names.
('A name <to@example.com>', 'ascii', 'A name <to@example.com>'),
('A name <to@example.com>', 'utf-8', '=?utf-8?q?A_name?= <to@example.com>'),
('"A name" <to@example.com>', 'ascii', 'A name <to@example.com>'),
('"A name" <to@example.com>', 'utf-8', '=?utf-8?q?A_name?= <to@example.com>'),
# Unicode addresses (supported per RFC-6532). # Unicode addresses (supported per RFC-6532).
('tó@example.com', 'utf-8', '=?utf-8?b?dMOz?=@example.com'), ('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'), ('Tó Example', 'tó@example.com'),
'utf-8', 'utf-8',
'=?utf-8?q?T=C3=B3_Example?= <=?utf-8?b?dMOz?=@example.com>', '=?utf-8?q?T=C3=B3_Example?= <=?utf-8?b?dMOz?=@example.com>',
), ),
# Unicode addresses with display names.
(
'Tó Example <tó@example.com>',
'utf-8',
'=?utf-8?q?T=C3=B3_Example?= <=?utf-8?b?dMOz?=@example.com>',
),
('To Example <to@éxample.com>', 'ascii', 'To Example <to@xn--xample-9ua.com>'),
(
'To Example <to@éxample.com>',
'utf-8',
'=?utf-8?q?To_Example?= <to@xn--xample-9ua.com>',
),
# Addresses with two @ signs.
('"to@other.com"@example.com', 'utf-8', r'"to@other.com"@example.com'),
(
'"to@other.com" <to@example.com>',
'utf-8',
'=?utf-8?q?to=40other=2Ecom?= <to@example.com>',
),
): ):
with self.subTest(email_address=email_address, encoding=encoding): with self.subTest(email_address=email_address, encoding=encoding):
self.assertEqual(sanitize_address(email_address, encoding), expected_result) self.assertEqual(sanitize_address(email_address, encoding), expected_result)