Skip to content

Commit 0119ca1

Browse files
committed
simplify error messaging
1 parent 9c70b12 commit 0119ca1

File tree

2 files changed

+6
-16
lines changed

2 files changed

+6
-16
lines changed

src/sentry/utils/display_name_filter.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,7 @@ def _has_cta(lowered: str) -> bool:
9090
def check_spam_display_name(name: str) -> str | None:
9191
"""Return an error string if the name matches 2+ spam categories, else None."""
9292
lowered = name.lower()
93-
matched_labels: list[str] = [label for label, check in _CATEGORIES if check(lowered)]
94-
if len(matched_labels) >= 2:
95-
joined = " and ".join(matched_labels)
96-
return f"This name contains disallowed content ({joined}). Please choose a different name."
93+
matched = sum(1 for _, check in _CATEGORIES if check(lowered))
94+
if matched >= 2:
95+
return "This name contains disallowed content. Please choose a different name."
9796
return None

tests/sentry/utils/test_display_name_filter.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,16 @@ def test_single_shorturl_signal_passes(self) -> None:
2121
assert check_spam_display_name("bit.ly/promo team") is None
2222

2323
def test_currency_plus_cta_rejected(self) -> None:
24-
result = check_spam_display_name("Free BTC - Click Here")
25-
assert result is not None
26-
assert "cryptocurrency terminology" in result
27-
assert "call-to-action phrases" in result
24+
assert check_spam_display_name("Free BTC - Click Here") is not None
2825

2926
def test_currency_plus_shorturl_rejected(self) -> None:
30-
result = check_spam_display_name("Earn $100 via 2g.tel/promo")
31-
assert result is not None
32-
assert "cryptocurrency terminology" in result
33-
assert "URL shortener domains" in result
27+
assert check_spam_display_name("Earn $100 via 2g.tel/promo") is not None
3428

3529
def test_shorturl_without_slash_not_matched(self) -> None:
3630
assert check_spam_display_name("support.com Solutions") is None
3731

3832
def test_cta_plus_shorturl_rejected(self) -> None:
39-
result = check_spam_display_name("Click Here: bit.ly/free")
40-
assert result is not None
41-
assert "call-to-action phrases" in result
42-
assert "URL shortener domains" in result
33+
assert check_spam_display_name("Click Here: bit.ly/free") is not None
4334

4435
def test_bare_shorturl_domain_without_path_passes(self) -> None:
4536
assert check_spam_display_name("Free BTC bit.ly") is None

0 commit comments

Comments
 (0)