Skip to content

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

Open

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

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