Skip to content

Set ascii_email for an empty local part - #201

Open
imsurya26 wants to merge 1 commit into
JoshData:mainfrom
imsurya26:fix/syntax-hunt
Open

imsurya26 wants to merge 1 commit into
JoshData:mainfrom
imsurya26:fix/syntax-hunt

Conversation

@imsurya26

Copy link
Copy Markdown

With allow_empty_local=True, an address with an empty local part gets ascii_email=None, although it is entirely ASCII:

>>> v = validate_email("@example.com", allow_empty_local=True, check_deliverability=False)
>>> v.ascii_local_part, v.smtputf8, v.ascii_email
('', False, None)

The README says ascii_email is present whenever an ASCII-only form exists, and this worked before 2.4.0. b505723 changed the condition from if not ret.smtputf8: to if ret.ascii_local_part and ret.ascii_domain:, and '' is falsy. This PR tests ret.ascii_local_part is not None instead. None is what marks a local part with no ASCII form, so b505723's intent (ascii_email together with smtputf8 after NFC normalization) is unchanged.

After the change: @example.com → @example.com, @exämple.com → @xn--exmple-cua.com, quoted ""@example.com → @example.com. A non-ASCII local part such as ö@example.com still gets ascii_email=None.

Tests: extended test_email_empty_local (fails without the change, passes with it). pytest tests/test_syntax.py tests/test_main.py -m "not network": 330 passed. flake8 with the Makefile flags is clean.

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.
@JoshData

Copy link
Copy Markdown
Owner

Can you combine this with the test on the previous line? There doesn't seem to be a need to call validate_email a second time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants