Skip to content

Commit ee485a4

Browse files
committed
Remove exactly one closing angle bracket after a display name
rstrip('>') removed any number of them, so 'Me <me@example.com>>' was accepted.
1 parent c0cc1bc commit ee485a4

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

‎email_validator/syntax.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ def unquote_quoted_string(text: str) -> tuple[str, bool]:
178178
raise EmailSyntaxError("There can't be anything after the email address.")
179179

180180
# Remove the initial and trailing angle brackets.
181-
addr_spec = right_part[1:].rstrip(">")
181+
addr_spec = right_part[1:-1]
182182

183183
# Split the email address at the first unquoted @-sign.
184184
local_part, domain_part = split_string_at_unquoted_special(addr_spec, ("@",))

‎tests/test_syntax.py‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,20 @@ def test_email_invalid_syntax_strict(email_input: str, error_msg: str) -> None:
518518
assert str(exc_info.value) == error_msg
519519

520520

521+
@pytest.mark.parametrize(
522+
'email_input',
523+
[
524+
'<me@example.com>>',
525+
'Display Name <me@example.com>>',
526+
'Display Name <me@example.com>>>',
527+
])
528+
def test_email_invalid_syntax_display_name(email_input: str) -> None:
529+
# Only one close angle bracket may follow the address.
530+
with pytest.raises(EmailSyntaxError) as exc_info:
531+
validate_email(email_input, check_deliverability=False, allow_display_name=True)
532+
assert str(exc_info.value) == "The part after the @-sign contains invalid characters: '>'."
533+
534+
521535
@pytest.mark.parametrize(
522536
'email_input',
523537
[

0 commit comments

Comments
 (0)