Skip to content

fix: preserve percent-encoding in external markdown links#308738

Open
maruthang wants to merge 1 commit intomicrosoft:mainfrom
maruthang:fix/issue-245128-markdown-url-text-fragment
Open

fix: preserve percent-encoding in external markdown links#308738
maruthang wants to merge 1 commit intomicrosoft:mainfrom
maruthang:fix/issue-245128-markdown-url-text-fragment

Conversation

@maruthang
Copy link
Copy Markdown
Contributor

Fixes #245128

Summary

Bug: Ctrl+clicking a markdown link with a text fragment (e.g. https://ffmpeg.org/ffmpeg-all.html#:~:text=%2Dversion) incorrectly decodes percent-encoded characters, breaking the URL.

Root Cause: The MdLinkOpener constructs a vscode.Uri via vscode.Uri.from() for all link types, including external URLs. The Uri constructor decodes percent-encoded characters (e.g. %2D to -, %2F to /) and re-encodes them differently, which breaks text fragment directives and other encoding-sensitive URL components.

Fix: For external links, pass the original linkText string directly to the vscode.open command instead of constructing a vscode.Uri. The vscode.open command already supports string arguments, so the URL is opened with its original encoding preserved.

Changes

  • extensions/markdown-language-features/src/util/openDocumentLink.ts: Handle external links before URI construction by passing the raw linkText string to vscode.open, preserving percent-encoding
  • extensions/markdown-language-features/src/test/openDocumentLink.test.ts (new): Regression tests verifying that percent-encoding is preserved in text fragments, query strings, and Firebase-style URLs

Test Plan

  • Added regression test that verifies vscode.Uri decodes %2D in fragments (demonstrating the bug)
  • Added test for percent-encoding preservation in query strings
  • Added test for Firebase-style URLs with %2F in paths
  • Existing tests should continue to pass as internal/file links are unaffected

…245128)

Pass external link URLs as raw strings to `vscode.open` instead of
constructing a `vscode.Uri`, which decodes and re-encodes percent-encoded
characters (e.g. `%2D` to `-`, `%2F` to `/`), breaking text fragment
directives and encoding-sensitive URL components.

Fixes microsoft#245128
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.

Markdown URL with text fragment falsely decoded when opening with ctrl + click in editor

2 participants