fix(links): stop mangling percent-encoding when opening relative + external links - #288
Merged
Conversation
…o Uri.parse mangling)
mtskf
force-pushed
the
fix/link-open-percent-encoding
branch
from
July 29, 2026 03:33
5758f37 to
c0bf0a9
Compare
…mment Adds a regression test proving the post-decode isAllowedUrl re-check in handleOpenLink actually gates something (removing it turns the test red), a mixed-valid/invalid-escape fallback test, and an e2e test proving buildExternalUri's Uri.parse fallback doesn't silently kill the open-external flow when the WHATWG parser rejects the href. Also corrects two stale comments in handle-open-external.ts that still described the pre-buildExternalUri `Uri.parse(url)` closure.
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.
What & why
Link opening mangled percent-encoding in both directions. Two localized host-side fixes:
(a) Relative links —
handle-open-link.ts[notes](my%20notes.md)(the standard form VS Code preview / GitHub / Obsidian emit) resolved to a literal%20-named file and failed to open. The host now percent-decodes the destination once before theUri.joinPathresolve. Security is preserved: the#fragmentis split on the encoded string first (a literal#in a filename is%23), decoding falls back to the raw form on a malformed escape (50%off.md), and every structural guard plus the workspace/containment check runs on the decoded, resolved target — so a decoded../traversal (..%2f..%2f…) resolves outside scope and is rejected.decodeURIComponentis all-or-nothing, so a path mixing valid + invalid escapes falls back to raw (not-found toast, no security impact).(b) External links —
build-external-uri.ts(new) +quoll-editor-panel.tsenv.openExternal(Uri.parse(url))decoded%2F→/at parse time (unrecoverable) — silently rewriting GitLab-style API paths and+-bearing queries. The URL is now split with the WHATWGURLparser (which preserves percent-encoding in path/query/fragment, incl. userinfo) and rebuilt viaUri.from({…}). VS Code's OpenerService delivers it asencodeURI(uri.toString(true))— skipEncoding, which leaves%2F/+intact — so the destination reaches the browser byte-exact for those chars. Malformed URLs the WHATWG parser rejects fall back to the priorUri.parsepath.Tests
handle-open-link.test.ts);%2F/+/%20/mailto/userinfo/password-only/null split (build-external-uri.test.ts).vscode.Uri):my%20notes.mdresolves the space-named target and..%2f…stays rejected under realUri.joinPath; the external byte-exact%2F++case captured through the real production handoff (theopenExternalOverrideseam now receives the builtUri).pnpm compile+pnpm test:unit(4081) + lint +pnpm test:e2e(100) all green.Notes
build-external-uri.tsadded to thenew URL(security choke-point allowlist (required lockstep).encodeURI(toString(true))opener behaviour (read from 1.130.0 source; a long-stable trait, documented in-code with a re-verify note).