From ba072458b5984a4afd4c28a95d6004453fa3b436 Mon Sep 17 00:00:00 2001 From: imsurya26 <219236223+imsurya26@users.noreply.github.com> Date: Fri, 20 Nov 2026 19:08:23 +0530 Subject: [PATCH] Set ascii_email for an empty local part With allow_empty_local=True, validate_email('@example.com') returned ascii_email=None although the address is ASCII. Since b505723 the check is a truthiness test on ascii_local_part, and an empty local part is ''. Test for None instead, which is what marks a non-ASCII local part. --- email_validator/validate_email.py | 2 +- tests/test_syntax.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/email_validator/validate_email.py b/email_validator/validate_email.py index eafe348..1288855 100644 --- a/email_validator/validate_email.py +++ b/email_validator/validate_email.py @@ -179,7 +179,7 @@ def validate_email( ret.normalized = ret.local_part + "@" + ret.domain # If the email address has an ASCII form, add it. - if ret.ascii_local_part and ret.ascii_domain: + if ret.ascii_local_part is not None and ret.ascii_domain: ret.ascii_email = (ret.ascii_local_part or "") + "@" + ret.ascii_domain else: ret.ascii_email = None diff --git a/tests/test_syntax.py b/tests/test_syntax.py index 257b246..f4796ab 100644 --- a/tests/test_syntax.py +++ b/tests/test_syntax.py @@ -674,6 +674,11 @@ def test_email_invalid_character_smtputf8_off(email_input: str, expected_error: def test_email_empty_local() -> None: validate_email("@test", allow_empty_local=True, test_environment=True) + # An empty local part is ASCII, so the ASCII form of the address is set. + validated = validate_email("@example.com", allow_empty_local=True, check_deliverability=False) + assert validated.ascii_local_part == "" + assert validated.ascii_email == "@example.com" + # This next one might not be desirable. validate_email("\"\"@test", allow_empty_local=True, allow_quoted_local=True, test_environment=True)