diff --git a/email_validator/syntax.py b/email_validator/syntax.py index 0a06840..f7e49e2 100644 --- a/email_validator/syntax.py +++ b/email_validator/syntax.py @@ -178,7 +178,7 @@ def unquote_quoted_string(text: str) -> tuple[str, bool]: raise EmailSyntaxError("There can't be anything after the email address.") # Remove the initial and trailing angle brackets. - addr_spec = right_part[1:].rstrip(">") + addr_spec = right_part[1:-1] # Split the email address at the first unquoted @-sign. local_part, domain_part = split_string_at_unquoted_special(addr_spec, ("@",)) diff --git a/tests/test_syntax.py b/tests/test_syntax.py index a322f4e..8f73038 100644 --- a/tests/test_syntax.py +++ b/tests/test_syntax.py @@ -518,6 +518,20 @@ def test_email_invalid_syntax_strict(email_input: str, error_msg: str) -> None: assert str(exc_info.value) == error_msg +@pytest.mark.parametrize( + 'email_input', + [ + '>', + 'Display Name >', + 'Display Name >>', + ]) +def test_email_invalid_syntax_display_name(email_input: str) -> None: + # Only one close angle bracket may follow the address. + with pytest.raises(EmailSyntaxError) as exc_info: + validate_email(email_input, check_deliverability=False, allow_display_name=True) + assert str(exc_info.value) == "The part after the @-sign contains invalid characters: '>'." + + @pytest.mark.parametrize( 'email_input', [