Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/validators/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def email(
# quoted-string
+ r'|^"('
+ r"[\u0100-\u017F\u0180-\u024F\u00A0-\u00FF\001-\010\013\014\016-\037"
+ r"!#-\[\]-\177]|\\[\011.]"
+ r"!#-\[\]-\177]|\\[\001-\011\013\014\016-\177]"
+ r')*")$',
username_part,
re.IGNORECASE,
Expand Down
2 changes: 1 addition & 1 deletion src/validators/url.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def _username_regex():
# dot-atom
+ r"|[-!#$%&'*+/=?^_`{}|~0-9a-z]+(\.[-!#$%&'*+/=?^_`{}|~0-9a-z]+)*$"
# non-quoted-string
+ r"|^([\001-\010\013\014\016-\037!#-\[\]-\177]|\\[\011.])*$)",
+ r"|^([\001-\010\013\014\016-\037!#-\[\]-\177]|\\[\001-\011\013\014\016-\177])*$)",
re.IGNORECASE,
)

Expand Down
6 changes: 6 additions & 0 deletions tests/test_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,9 @@ def test_rejects_newline_after_local_part(local_part: str):
def test_returns_failed_validation_on_idna_mapped_lookalike_domain(domain_part: str):
"""Test returns failed validation on email domains that only IDNA 2003 mapping makes valid."""
assert isinstance(email(f"user@{domain_part}"), ValidationError)


@pytest.mark.parametrize("local_part", [r'"a\"b"', r'"a\\b"', r'"\a"', r'"a\ b"'])
def test_accepts_quoted_pair_with_any_visible_character(local_part: str):
"""Test a backslash may escape any visible character or space (RFC 5322 3.2.1)."""
assert email(f"{local_part}@example.com")