From 5cdcb9e26f832edd7ae9b84f1c566842c49343f0 Mon Sep 17 00:00:00 2001 From: 0xbyt4 <35742124+0xbyt4@users.noreply.github.com> Date: Sat, 7 Mar 2026 18:55:25 +0300 Subject: [PATCH] fix: strip MarkdownV2 italic markers in Telegram plaintext fallback When MarkdownV2 parsing fails, _strip_mdv2() removes escape backslashes and bold markers (*text*) but missed italic markers (_text_). Users saw raw underscores around italic text in the plaintext fallback. - Add regex to strip _text_ italic markers in _strip_mdv2() - Use word boundary lookaround to preserve snake_case identifiers - Add tests for _strip_mdv2 covering italic, bold, snake_case, and edge cases --- gateway/platforms/telegram.py | 3 +++ tests/gateway/test_telegram_format.py | 34 ++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/gateway/platforms/telegram.py b/gateway/platforms/telegram.py index 9ed47a39..02993d5e 100644 --- a/gateway/platforms/telegram.py +++ b/gateway/platforms/telegram.py @@ -86,6 +86,9 @@ def _strip_mdv2(text: str) -> str: cleaned = re.sub(r'\\([_*\[\]()~`>#\+\-=|{}.!\\])', r'\1', text) # Remove MarkdownV2 bold markers that format_message converted from **bold** cleaned = re.sub(r'\*([^*]+)\*', r'\1', cleaned) + # Remove MarkdownV2 italic markers that format_message converted from *italic* + # Use word boundary (\b) to avoid breaking snake_case like my_variable_name + cleaned = re.sub(r'(?