Skip to content

gh-101034: Clarify error for email domain ending with a dot#151972

Open
tonghuaroot wants to merge 1 commit into
python:mainfrom
tonghuaroot:gh-101034-domain-trailing-dot-error
Open

gh-101034: Clarify error for email domain ending with a dot#151972
tonghuaroot wants to merge 1 commit into
python:mainfrom
tonghuaroot:gh-101034-domain-trailing-dot-error

Conversation

@tonghuaroot

@tonghuaroot tonghuaroot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

email.headerregistry.Address(addr_spec="user@example.org.") (a domain ending
in a dot) raises a cryptic HeaderParseError: expected atext but found '' that
gives no hint about the trailing dot.

Per RFC 5322 the rejection is correct -- dot-atom / obs-domain both require
an atom after every ., so a trailing-dot domain isn't a valid addr-spec
domain. The only defect is the message: in _header_value_parser.get_domain,
the obs-domain fallback reaches the final . and calls get_atom(''), which
surfaces that bare internal error.

This raises a clear HeaderParseError("expected atom after '.' but found end of domain") instead. Behavior is unchanged (the trailing-dot domain is still
rejected); only the diagnostic improves -- the "more informative error"
requested in the issue.

If email should instead accept the FQDN-root trailing dot, that is a
behavior change that deserves its own issue and need not block this diagnostic
fix.

Issue: #101034

get_domain's obs-domain loop called get_atom on an empty string after a
trailing dot, surfacing the internal "expected atext but found ''"
instead of a meaningful message. Raise a clear HeaderParseError instead.
A trailing-dot domain remains invalid per the RFC 5322 dot-atom and
obs-domain grammars; only the diagnostic changes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant