Fix to 'Markdown Preview of relative links drops 'host' from path' #95092
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.
This PR fixes #93961.
Explanation
The
URI
class holds different information in thepath
property when the file was opened through a UNC location. For this fix I used the propertyfsPath
instead ofpath
in theonDidClickPreviewLink
handler.For a local file the
URI
class holds:where as for a UNC opened file the
URI
class holds:Here is an excerpt from
uri.ts
:foo://example.com:8042/over/there?name=ferret#nose \_/ \______________/\_________/ \_________/ \__/ | | | | | scheme authority path query fragment | _____________________|__ / \ / \ urn:example:animal:ferret:nose
Test the issue and the fix:
To test this issue create two md files (see below this list).
Open the
readme.md
file with an UNC path like"\\server\sharedfolder\readme.md"
.Open the preview of the markdown file
readme.md
.In the preview window, click on the
Relative link to TEST.md
link.The
test.md
file should open in the preview. Without the fix, an error message is being shown.Test files
readme.md:
Here's a link: [Relative link to TEST.md](TEST.md)
test.md:
This is the test markdown file