Skip to content

fix(email, url): accept quoted pairs with any visible character again - #585

Closed
yuchengshen931122-creator wants to merge 1 commit into
python-validators:masterfrom
yuchengshen931122-creator:g33/fix-quoted-pair
Closed

yuchengshen931122-creator wants to merge 1 commit into
python-validators:masterfrom
yuchengshen931122-creator:g33/fix-quoted-pair

Conversation

@yuchengshen931122-creator

Copy link
Copy Markdown

Fixes #582.

What

af69a68 changed the quoted-pair class in the local-part regex from \\[\001-\011\013\014\016-\177] to \\[\011.]. Inside [...] the . is a literal dot, so only backslash-TAB and backslash-dot were accepted and "a\"b"@example.com was rejected. This restores the previous class (the one Django uses) in email.py and in url.py (_username_regex, same change in the same commit).

Behaviour

  • "a\"b", "a\\b", "\a", "a\ b" as local parts: now valid (RFC 5322 §3.2.1, quoted-pair = "\" (VCHAR / WSP)).
  • Existing expectations are unchanged: "\<TAB>" stays valid, "\<LF>" and "\<CR>" stay invalid (test_returns_failed_validation_on_invalid_email).

Tests

  • New: test_accepts_quoted_pair_with_any_visible_character (4 cases) – fails on master, passes with this change.
  • 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

af69a68 changed the quoted-pair class from `\[\001-\011\013\014\016-\177]`
to `\[\011.]`. Inside a character class `.` is a literal dot, so only
backslash-TAB and backslash-dot were accepted and `"a\\"b"@example.com` was
rejected. Restore the previous class (the one Django uses); escaped LF/CR
stay invalid, so existing expectations are unchanged.

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

Copy link
Copy Markdown
Author

Closing this in favour of #581, which was opened a few minutes before ours for the same regression of af69a68.

One part of this pull request is wrong and should not be merged from here. It also changes _username_regex in url.py, and with that change a backslash and a double quote are accepted in the user name of a URL:

>>> url('http://a\\"b@example.com/')   # master and #581: ValidationError; this branch: True

RFC 3986 section 3.2.1 has no quoted pair (userinfo = *( unreserved / pct-encoded / sub-delims / ":" )), so url() is right to reject that today. #581 leaves url.py alone, which is the correct scope.

Sorry for the duplicate; we should have searched the tracker first. (Checked by running master, #581 and this branch; this text was prepared with the help of an AI assistant.)

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: quoted pairs only accept \<TAB> and \. since af69a68, so "a\"b"@example.com is rejected

1 participant