Skip to content

Commit e01166b

Browse files
fhgffynandgator
authored andcommitted
Reject a trailing newline in email local parts
1 parent 31a670b commit e01166b

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

‎src/validators/email.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def email(
8383
rfc_2782=rfc_2782,
8484
)
8585
)
86-
if re.match(
86+
if re.fullmatch( # 2026-10-11: Validate the complete local part.
8787
# extended latin
8888
r"(^[\u0100-\u017F\u0180-\u024F\u00A0-\u00FF]"
8989
# dot-atom

‎tests/test_email.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,13 @@ def test_returns_true_on_valid_email(value: str):
5656
def test_returns_failed_validation_on_invalid_email(value: str):
5757
"""Test returns failed validation on invalid email."""
5858
assert isinstance(email(value), ValidationError)
59+
60+
61+
@pytest.mark.parametrize(
62+
"local_part", ["person", "person.name", "\u0141\u00f3ka\u015b\u0107", '"person"']
63+
)
64+
def test_rejects_newline_after_local_part(local_part: str):
65+
"""Test the whole local part, including its final character."""
66+
# 2026-10-11: A newline before the at-sign is not part of a valid local part.
67+
assert email(f"{local_part}@example.com") is True
68+
assert isinstance(email(f"{local_part}\n@example.com"), ValidationError)

0 commit comments

Comments
 (0)