Skip to content

fix(telegram): escape bare parentheses/braces in MarkdownV2 output#2386

Merged
teknium1 merged 1 commit intomainfrom
hermes/hermes-40b195db
Mar 21, 2026
Merged

fix(telegram): escape bare parentheses/braces in MarkdownV2 output#2386
teknium1 merged 1 commit intomainfrom
hermes/hermes-40b195db

Conversation

@teknium1
Copy link
Copy Markdown
Contributor

From bitfalt's gateway logs: 77 MarkdownV2 parse failures, all 'character ( is reserved and must be escaped'. Every long response with parentheses fell back to plain text, losing all formatting.

The MarkdownV2 conversion (format_message) correctly escapes parens in step 10, but edge cases in placeholder processing left some unescaped — partial link matches, URLs with parens in them, etc.

Fix: Added step 12 after placeholder restoration — a safety-net pass that catches any remaining bare ( ) { } outside code blocks and valid link syntax, and escapes them. Splits text into code/non-code segments first so code block contents are never touched.

114 Telegram tests pass.

The MarkdownV2 format_message conversion left unescaped ( ) { }
in edge cases where placeholder processing didn't cover them (e.g.
partial link matches, URLs with parens). This caused Telegram to
reject the message with 'character ( is reserved and must be escaped'
and fall back to plain text — losing all formatting.

Added a safety-net pass (step 12) after placeholder restoration that
escapes any remaining bare ( ) { } outside code blocks and valid
MarkdownV2 link syntax.
@teknium1 teknium1 merged commit 81dbf43 into main Mar 21, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant