fix: preserve percent-encoding in external markdown links#308738
Open
maruthang wants to merge 1 commit intomicrosoft:mainfrom
Open
fix: preserve percent-encoding in external markdown links#308738maruthang wants to merge 1 commit intomicrosoft:mainfrom
maruthang wants to merge 1 commit intomicrosoft:mainfrom
Conversation
…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
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.
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
MdLinkOpenerconstructs avscode.Uriviavscode.Uri.from()for all link types, including external URLs. The Uri constructor decodes percent-encoded characters (e.g.%2Dto-,%2Fto/) and re-encodes them differently, which breaks text fragment directives and other encoding-sensitive URL components.Fix: For external links, pass the original
linkTextstring directly to thevscode.opencommand instead of constructing avscode.Uri. Thevscode.opencommand 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 rawlinkTextstring tovscode.open, preserving percent-encodingextensions/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 URLsTest Plan
vscode.Uridecodes%2Din fragments (demonstrating the bug)%2Fin paths