summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2023-07-17 11:03:36 +0200
committerGitHub <noreply@github.com>2023-07-17 11:03:36 +0200
commitda2f8e8257d1bea4215381684ca4abfcee333c43 (patch)
tree22d50ec8b55d808967c4a5e86c21a3593d4a5ed6
parent0016a4299569a8f09ff24053ff2b8224f7fa4113 (diff)
Refs #34118 -- Improved sanitize_address() error message for tuple with empty strings.
-rw-r--r--django/core/mail/message.py2
-rw-r--r--tests/mail/tests.py3
2 files changed, 4 insertions, 1 deletions
diff --git a/django/core/mail/message.py b/django/core/mail/message.py
index f3fe6186c7..4f8c93e9e5 100644
--- a/django/core/mail/message.py
+++ b/django/core/mail/message.py
@@ -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
diff --git a/tests/mail/tests.py b/tests/mail/tests.py
index 54a136c1a9..848ee32e9f 100644
--- a/tests/mail/tests.py
+++ b/tests/mail/tests.py
@@ -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):