Refs #34118 -- Improved sanitize_address() error message for tuple with empty strings.

This commit is contained in:
Mariusz Felisiak 2023-07-17 11:03:36 +02:00 committed by GitHub
parent 0016a42995
commit da2f8e8257
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 1 deletions

View File

@ -97,6 +97,8 @@ def sanitize_address(addr, encoding):
domain = token.domain or ""
else:
nm, address = addr
if "@" not in address:
raise ValueError(f'Invalid address "{address}"')
localpart, domain = address.rsplit("@", 1)
address_parts = nm + localpart + domain

View File

@ -1084,9 +1084,10 @@ class MailTests(HeadersCheckMixin, SimpleTestCase):
"@",
"to@",
"@example.com",
("", ""),
):
with self.subTest(email_address=email_address):
with self.assertRaises(ValueError):
with self.assertRaisesMessage(ValueError, "Invalid address"):
sanitize_address(email_address, encoding="utf-8")
def test_sanitize_address_header_injection(self):