From 4eab312c35970360e2cd0725ca081e7f6965b9b0 Mon Sep 17 00:00:00 2001 From: Tranquil-Flow Date: Sat, 25 Apr 2026 09:55:22 +1000 Subject: [PATCH] fix(gateway): fix underscore-stripping regex to preserve snake_case identifiers The blanket _(.+?)_ and __(.+?)__ patterns incorrectly consumed snake_case identifiers like send_as_bot and user_id. Add lookbehind/lookahead boundaries so underscores adjacent to alphanumeric characters are not treated as markdown formatting. Same fix already applied and tested in the CLI renderer; this addresses the gateway/platforms/helpers.py copy. Supersedes #15076. --- gateway/platforms/helpers.py | 4 +- .../test_helpers_markdown_underscore.py | 60 +++++++++++++++++++ 2 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 tests/gateway/test_helpers_markdown_underscore.py diff --git a/gateway/platforms/helpers.py b/gateway/platforms/helpers.py index 18d97fcb7a..1282b76232 100644 --- a/gateway/platforms/helpers.py +++ b/gateway/platforms/helpers.py @@ -157,8 +157,8 @@ class TextBatchAggregator: # Pre-compiled regexes for performance _RE_BOLD = re.compile(r"\*\*(.+?)\*\*", re.DOTALL) _RE_ITALIC_STAR = re.compile(r"\*(.+?)\*", re.DOTALL) -_RE_BOLD_UNDER = re.compile(r"__(.+?)__", re.DOTALL) -_RE_ITALIC_UNDER = re.compile(r"_(.+?)_", re.DOTALL) +_RE_BOLD_UNDER = re.compile(r"(?