Skip to content

fix(email): accept exactly one pair of brackets around address literals - #586

Open
yuchengshen931122-creator wants to merge 1 commit into
python-validators:masterfrom
yuchengshen931122-creator:g33/fix-email-address-literal-brackets
Open

yuchengshen931122-creator wants to merge 1 commit into
python-validators:masterfrom
yuchengshen931122-creator:g33/fix-email-address-literal-brackets

Conversation

@yuchengshen931122-creator

Copy link
Copy Markdown

Fixes #583.

What

email unwrapped address literals with domain_part.lstrip("[").rstrip("]"), which removes any number of brackets, so user@[[192.168.0.1]] and the unbalanced user@[[192.168.0.1] were valid with ipv4_address=True. RFC 5321 §4.1.3 allows exactly one pair. The literal is now unwrapped with domain_part[1:-1]; anything left over makes the IP check fail.

Tests

  • New: test_rejects_extra_brackets_around_address_literal (4 cases, IPv4 and IPv6) – fails on master, passes with this change; it also checks that a single pair is still accepted.
  • Checked locally with the CI commands: uv run pytest . (1,578 passed), ruff format ., ruff check ., pyright . (0 errors).

Found while writing specification-based tests for a university software-testing project (NYCU). The change and this description were prepared with the help of an AI assistant (Claude Code).

🤖 Generated with Claude Code

`lstrip("[")`/`rstrip("]")` removed any number of brackets, so
`user@[[192.168.0.1]]` and even `user@[[192.168.0.1]` were valid with
`ipv4_address=True`. RFC 5321 4.1.3 allows exactly one pair.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

email: address literals with extra brackets are accepted (user@[[192.168.0.1]])

1 participant