fix(telegram): keep link URLs intact when rendering Markdown to HTML - #5960
Merged
Merged
Conversation
Re-bin
force-pushed
the
fix/telegram-link-url-formatting
branch
from
October 2, 2026 15:07
36757b2 to
b41481f
Compare
Re-bin
force-pushed
the
fix/telegram-link-url-formatting
branch
from
October 3, 2026 07:39
b41481f to
c877f26
Compare
Bold, italic and strikethrough passes ran over generated href attributes, so URLs such as .../__init__.py became .../<b>init</b>.py and Telegram rejected or mis-linked the message. Protect URLs with placeholders until inline formatting is done and escape double quotes inside href.
Re-bin
force-pushed
the
fix/telegram-link-url-formatting
branch
from
October 3, 2026 09:52
c877f26 to
d4a3a24
Compare
Re-bin
approved these changes
Oct 3, 2026
Re-bin
left a comment
Collaborator
There was a problem hiding this comment.
Keeps Telegram link destinations intact while preserving label formatting and escaping attribute quotes. Channel regression coverage and current-head CI pass.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix Telegram Markdown→HTML rendering corrupting link URLs. Links whose URL contains
__,_word_,**or~~were rewritten by the inline-formatting passes, and a"in the URL broke out of thehrefattribute.Root Cause
_markdown_to_telegram_htmlconverts[text](url)to<a href="url">text</a>in step 6, then runs the bold / italic / strikethrough regexes over the whole string in steps 7–9 — including the freshly generatedhrefvalues._escape_telegram_htmlalso does not escape", which is needed inside a double-quoted attribute.[init](https://github.com/o/r/blob/main/pkg/__init__.py)href=".../pkg/<b>init</b>.py"href=".../pkg/__init__.py"[css](https://example.com/_static_/a.css)href="https://example.com/<i>static</i>/a.css"[q](https://example.com/?q="x")href="https://example.com/?q="x""href="https://example.com/?q="x""Links to
__init__.py,__main__.py, dunder paths and_static_asset folders are common in coding-agent replies, so these messages end up with broken links or a Telegramcan't parse entitiesrejection.Changes
\x00LK{i}\x00placeholder (same technique already used for code blocks and inline code) and restore it after the inline-formatting passes."as"inside the stored URL.[**bold** _it_](url)keeps rendering as<a href="url"><b>bold</b> <i>it</i></a>.Result
Link URLs reach Telegram byte-for-byte (HTML-escaped). Rendering of non-link text is unchanged.
Test
_static_URL,**/~~URL, quoted URL) failed before the fix and pass afterward; the link-text formatting case passes both before and after, guarding against regressions.pytest nanobot/channels/telegram -q: 145 passed.ruff check nanobot/channels/telegram: passed.basedpyright nanobot/channels/telegram/runtime.py: 0 errors, 0 warnings.git diff --check: passed.