Skip to content

email() rejects escaped characters in quoted local parts #580

Open

Description

@uvrvuoon

email() rejects quoted local parts that use a backslash escape, except for \. and an escaped tab:

>>> import validators
>>> validators.email('"a\\"b"@example.com')
ValidationError(func=email, args={'value': '"a\\"b"@example.com'})
>>> validators.email('"a\\\\b"@example.com')
ValidationError(func=email, args={'value': '"a\\\\b"@example.com'})
>>> validators.email('"a\\.b"@example.com')
True

RFC 5322 section 3.2.1 defines a quoted-pair as a backslash followed by any VCHAR or WSP, so "a\"b"@example.com and "a\\b"@example.com are valid addresses.

This seems to come from af69a68 ("patch: supported extended latin in username"), which changed the quoted-pair part of the regex from \\[\001-\011\013\014\016-\177] to \\[\011.]. Inside a character class . only matches a literal dot, so only \. and an escaped tab are accepted now. Before that commit, "a\"b"@example.com validated as True.

If the narrower rule was intentional, please let me know. Otherwise I'd like to open a PR that accepts a backslash followed by a tab or any printable ASCII character, while still rejecting escaped control characters (so the existing "\<LF>" test still fails as expected).

Reproduced on master (22786cc), Python 3.14 on Windows.

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