Repository navigation
Conversation
1AbdullahButt
left a comment
There was a problem hiding this comment.
Checked the new pattern against the old one on a batch of domains (copied the two DOMAIN_REGEX variants into a small script):
| domain | main | this PR |
|---|---|---|
example.-com, example.com- |
accepted | rejected |
例え.-テスト, 例え.テスト- |
accepted | rejected |
example.--, example.1- |
accepted | rejected |
example.xn--p1ai, example.co-m |
accepted | accepted |
example.com, sub.example.museum |
accepted | accepted |
So the lookarounds only touch the last label, and punycode TLDs still pass.
A few small things:
user@ex-.comanduser@-ex.com(tests/test_validate.py) already fail onmain, since the earlier labels are anchored with[A-Z0-9…]at both ends. They're fine to keep as coverage, but they aren't regressions for #3072.- Possibly out of scope: an all-digit last label like
user@example.123is still accepted through the second alternative. It might be worth a follow-up issue if you want the TLD rules tightened further. - Recent fixes add a line to
CHANGELOG.rstunder the unreleased section ("Thanks :user:...for the PR"). That could be added here too.
Reviewed with help from Claude Code.
Author
|
Thanks for checking this against
|
Member
|
dupe, bot |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #3072.
validate.Emailpreviously allowed domain names with leading or trailing hyphens in the final domain label / TLD alternative (e.g.user@example.-com,user@example.com-,user@??.-???). Per RFC 5321 �4.1.2, domain labels must not start or end with a hyphen.This PR:
Email.DOMAIN_REGEXwith(?!-)at the start and(?<!-)at the end, ensuring that the label can neither start nor end with a hyphen.test_email_invalidandtest_email_idn_invalidintests/test_validate.py.Verification
pytest(1,198 passed in 1.75s).