fix: preserve Telegram usernames with underscores

This commit is contained in:
3252a8
2026-05-19 00:07:32 +03:00
parent 1d9f069f45
commit 3152631911
3 changed files with 37 additions and 6 deletions
+11 -4
View File
@@ -199,10 +199,17 @@ def sanitize_display_name(value: Optional[str]) -> Optional[str]:
def sanitize_username(value: Optional[str]) -> Optional[str]:
if value is None:
return None
clean = value.strip()
clean = clean.lstrip("@")
clean = _remove_patterns(clean)
return _finalize(clean)
clean = unicodedata.normalize("NFKC", str(value))
clean = clean.strip().lstrip("@").strip()
if not clean:
return None
# Telegram usernames are already a constrained identifier, not free-form display text.
# Do not apply display-name anti-spoofing filters here: they remove words like
# "service" or "support" from valid usernames such as "name_service".
if re.fullmatch(r"[A-Za-z0-9_-]{1,64}", clean):
return clean
return None
def username_for_display(username: Optional[str], with_at: bool = False) -> str: