Skip to content

fix(telegram): escape '(' in URLs for MarkdownV2 compatibility#1196

Closed
usvimal wants to merge 1 commit intoNousResearch:mainfrom
usvimal:fix/telegram-markdownv2-url-escaping
Closed

fix(telegram): escape '(' in URLs for MarkdownV2 compatibility#1196
usvimal wants to merge 1 commit intoNousResearch:mainfrom
usvimal:fix/telegram-markdownv2-url-escaping

Conversation

@usvimal
Copy link
Contributor

@usvimal usvimal commented Mar 13, 2026

Problem

Telegram's MarkdownV2 requires both '(' and ')' to be escaped in URLs. The previous code only escaped ')', causing parse failures for URLs containing '(' characters (common in query strings like ).

This resulted in messages falling back to plain text with warnings like:

Solution

Added to the URL escaping logic.

Changes

  • Line 626: Added '(' escaping in URL processing
  • Updated comment to correctly state that '(', ')', and '' need escaping per MarkdownV2 spec

This ensures URLs with parentheses are properly formatted and messages display with correct Markdown formatting instead of falling back to plain text.

Telegram's MarkdownV2 requires both '(' and ')' to be escaped in URLs.
The previous code only escaped ')', causing parse failures for URLs
containing '(' characters (common in query strings).

Changes:
- Added .replace('(', '\(') to URL escaping
- Updated comment to reflect correct escaping requirements

Fixes MarkdownV2 parse failures that caused messages to fall back to plain text.
@usvimal usvimal force-pushed the fix/telegram-markdownv2-url-escaping branch from 97f2e32 to 91ff48f Compare March 13, 2026 18:56
@teknium1
Copy link
Contributor

Thanks for the fix attempt here. I'm closing this because current main already matches Telegram's MarkdownV2 spec for inline-link URLs: inside the part, and must be escaped, but is not required. Telegram allows escaping extra ASCII characters, so escaping is permitted, but it isn't needed for correctness, and the updated comment in this PR would actually be less accurate than the current code. I also verified the current Telegram formatter tests pass on main.

@teknium1 teknium1 closed this Mar 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants