You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
email: quoted pairs only accept \<TAB> and \. since af69a68, so "a\"b"@example.com is rejected #582
Since af69a68 ("patch: supported extended latin in username", 2024-04-02) the quoted-pair part of the local-part regex in email is \\[\011.]. Inside a character class . is a literal dot, so a backslash can only escape a TAB or a .. Before that commit the class was \\[\001-\011\013\014\016-\177] (the same as Django's validator, which the docstring cites), i.e. any character except NUL, LF and CR. The same line was changed in url.py (_username_regex).
>>>fromvalidatorsimportemail>>>email(r'"a\"b"@example.com') # escaped double quoteValidationError(func=email, args={'value': '"a\\"b"@example.com'})
>>>email(r'"a\\b"@example.com') # escaped backslashValidationError(func=email, args={'value': '"a\\b"@example.com'})
>>>email(r'"a\.b"@example.com') # escaped dot is the only visible character acceptedTrue
Expected
RFC 5322 §3.2.1: quoted-pair = ("\" (VCHAR / WSP)) / obs-qp. Escaping a double quote or a backslash is the main use of quoted pairs, so both addresses above are valid.
Proposed fix
Restore the class used before af69a68 in email.py and in url.py. Existing expectations stay the same: "\<TAB>" is still valid, "\<LF>" and "\<CR>" are still invalid. A PR follows.
Found while writing specification-based tests for a university software-testing project (NYCU). The investigation and this write-up were done with the help of an AI assistant (Claude Code); the reproduction was run on the current master.
Activity