Skip to content

email: quoted pairs only accept \<TAB> and \. since af69a68, so "a\"b"@example.com is rejected #582

Duplicate

Description

Summary

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).

Reproduction (master at 22786cc, Python 3.13)

>>> from validators import email
>>> email(r'"a\"b"@example.com')      # escaped double quote
ValidationError(func=email, args={'value': '"a\\"b"@example.com'})
>>> email(r'"a\\b"@example.com')      # escaped backslash
ValidationError(func=email, args={'value': '"a\\b"@example.com'})
>>> email(r'"a\.b"@example.com')      # escaped dot is the only visible character accepted
True

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

  1. yuchengshen931122-creator commented on Nov 24, 2026

    @yuchengshen931122-creator
    Author

    Closing as a duplicate of #580, which reported the same regression a few minutes before this issue; the fix is in #581. Our own pull request #585 is closed as well (it also touched url.py, which was a mistake; details there).

    Sorry for the noise. (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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions