Skip to content

Commit dcc3218

Browse files
authored
Remove exactly one closing angle bracket after a display name (#176)
rstrip('>') removed any number of them, so 'Me <me@example.com>>' was accepted. Co-authored-by: youdie006 <youdie006@users.noreply.github.com>
1 parent 8ae8d01 commit dcc3218

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
@@ -528,6 +528,20 @@ def test_email_invalid_syntax_strict(email_input: str, error_msg: str) -> None:
528528
assert str(exc_info.value) == error_msg
529529

530530

531+
@pytest.mark.parametrize(
532+
'email_input',
533+
[
534+
'<me@example.com>>',
535+
'Display Name <me@example.com>>',
536+
'Display Name <me@example.com>>>',
537+
])
538+
def test_email_invalid_syntax_display_name(email_input: str) -> None:
539+
# Only one close angle bracket may follow the address.
540+
with pytest.raises(EmailSyntaxError) as exc_info:
541+
validate_email(email_input, check_deliverability=False, allow_display_name=True)
542+
assert str(exc_info.value) == "The part after the @-sign contains invalid characters: '>'."
543+
544+
531545
@pytest.mark.parametrize(
532546
'email_input',
533547
[

0 commit comments

Comments
 (0)