Fix live preview breaking on # in file or folder names - #857
Open
Tech Guy (lukiod) wants to merge 1 commit into
Open
Fix live preview breaking on # in file or folder names#857Tech Guy (lukiod) wants to merge 1 commit into
Tech Guy (lukiod) wants to merge 1 commit into
Conversation
PathUtil.EscapePathParts used encodeURI on each path segment, which deliberately leaves # unescaped (it's meant for encoding a full URI, where # is a structural delimiter, not an individual path segment). A folder or file name containing # therefore produced a preview URL where everything from # onward is treated by the browser as a fragment and never reaches the server, showing the parent directory listing instead of the file. Switched EscapePathParts/UnescapePathParts to encodeURIComponent/decodeURIComponent, which escape all reserved characters in a path segment rather than only some of them. Fixes microsoft#750
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.
Bug
PathUtil.EscapePathPartsescapes each path segment withencodeURI, which deliberately leaves#(and a few other reserved characters like?,&) unescaped — it's designed for encoding a full URI, where those characters are structural delimiters, not for encoding an individual path segment.A file or folder name containing
#therefore produces a preview URL where the browser treats everything from#onward as a fragment and never sends it to the server, so the file isn't found — the server falls back to showing the parent directory listing instead.Fix
Switched
EscapePathParts/UnescapePathPartstoencodeURIComponent/decodeURIComponent, which escape (and correctly reverse) all reserved characters in a path segment rather than only some of them.Verification
EscapePathParts/UnescapePathPartsdon't touch the VS Code API directly, so I could reproduce the exact old vs. new behavior standalone with Node's ownencodeURI/encodeURIComponent:Added 3 regression tests to
src/test/suite/pathUtil.test.tsfollowing the existing file'sdescribe/itpattern, covering escape, round-trip, and a leading#.tsc -p ./andeslint srcare both clean. I wasn't able to run the full Electron-based extension-host test suite in this environment (noXvfb, and installing one needs root here), so I'm disclosing that rather than claiming it — the new tests are pure (novscode.*calls, matching the neighboringgetEndpointParenttests in the same file) so they should run cleanly in CI.Fixes #750