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)