Skip to content

Accept escaped printable characters in quoted email local parts - #581

Open
uvrvuoon wants to merge 1 commit into
python-validators:masterfrom
uvrvuoon:fix/email-quoted-pair
Open

uvrvuoon wants to merge 1 commit into
python-validators:masterfrom
uvrvuoon:fix/email-quoted-pair

Conversation

@uvrvuoon

Copy link
Copy Markdown

Fixes #580.

email() only accepted \. and an escaped tab inside a quoted local part, so valid addresses such as "a\"b"@example.com and "a\\b"@example.com were rejected. The quoted-pair class was narrowed in af69a68, where \\[\001-\011\013\014\016-\177] became \\[\011.]. In a character class . is a literal dot.

This changes the quoted-pair to a backslash followed by a tab or any printable ASCII character (\x20–\x7E), following RFC 5322 section 3.2.1:

  • "a\"b", "a\\b", "a\ b", "\z" are now accepted
  • escaped control characters (NUL, LF, DEL) are still rejected, so the existing "\<LF>" test is unchanged
  • the class is wrapped in (?-i:...) so that re.IGNORECASE doesn't also let in characters like the Kelvin sign (U+212A), which case-folds to k

The same \\[\011.] pattern was also added to the username regex in url.py by af69a68. I left that alone here because URL userinfo has different rules; happy to look at it separately if wanted.

Tests: the four new valid cases fail before the change and pass after it. tox -e lint,format,type,py312,py314 passes on Windows (1,582 tests).

I used Claude to help investigate and draft this change.

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() rejects escaped characters in quoted local parts

1 participant