fix: prevent italic regex from spanning newlines in Telegram formatter

The italic regex \*([^*]+)\* used [^*] which matches newlines, causing
bullet lists with * markers to be incorrectly converted to italic text.
Changed to [^*\n]+ to prevent cross-line matching.

Adds 43 tests for _escape_mdv2 and format_message covering code blocks,
bold/italic, headers, links, mixed formatting, and the regression case.
This commit is contained in:
0xbyt4 2026-02-28 22:01:48 +03:00
parent 6366177118
commit b759602483
2 changed files with 365 additions and 1 deletions

View file

@ -372,8 +372,10 @@ class TelegramAdapter(BasePlatformAdapter):
)
# 6) Convert italic: *text* (single asterisk) → _text_ (MarkdownV2 italic)
# [^*\n]+ prevents matching across newlines (which would corrupt
# bullet lists using * markers and multi-line content).
text = re.sub(
r'\*([^*]+)\*',
r'\*([^*\n]+)\*',
lambda m: _ph(f'_{_escape_mdv2(m.group(1))}_'),
text,
)