Skip to content

Decode percent-encoded file paths in permalinks - #9097

Open
Ngo Quoc Viet (NgoQuocViet2001) wants to merge 1 commit into
microsoft:mainfrom
NgoQuocViet2001:fix-encoded-permalink-paths
Open

Ngo Quoc Viet (NgoQuocViet2001) wants to merge 1 commit into
microsoft:mainfrom
NgoQuocViet2001:fix-encoded-permalink-paths

Conversation

@NgoQuocViet2001

Copy link
Copy Markdown

Blob permalinks in the PR and issue overviews are opened locally only when fileExistsCheck finds the file. But processPermalinks takes the path straight from the href, where it is still percent-encoded. A link to docs/My Notes.md arrives as docs/My%20Notes.md, the lookup goes to a file literally named My%20Notes.md, and the link stays a plain GitHub link. The same happens for non-ASCII file names and for paths that "Copy GitHub Permalink" encodes, such as app/[slug]/page.tsx, which becomes app/%5Bslug%5D/page.tsx.

The path is now decoded before the existence check and before it is written to data-local-file. It is still HTML-escaped after decoding, so %22 ends up as ". The href is unchanged. A path that is not valid percent-encoding, like src/100%.md, is used as written, as before. prComment.replacePermalink and issueLinkLookup.findCodeLinkLocally have the same gap and are left for a separate change.

Ran:

  • npm run test:preprocess and node ./out/src/test/runTests.js: 1114 passing. The two new decoding tests fail without the fix.
  • npm run test:scripts (75 passing) and npm run test:webviews (96 passing)
  • npm run compile, npm run lint, npm run hygiene and npm run check:commands: clean

Blob permalinks carry the file path percent-encoded, so a link to
`docs/My%20Notes.md` was looked up as a file literally named
`My%20Notes.md` and never opened locally. Decode the path before the
existence check and the data-local-file attribute, and keep the raw
path when it is not valid percent-encoding.
Copilot AI balanced review requested due to automatic review settings October 24, 2026 18:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The focused fix preserves existing safety and fallback behavior, includes targeted regression tests, and has no identified blocking issues.

No open issues 🎉

What changed in this PR

Fixes local opening of blob permalinks in PR and issue overviews by decoding percent-encoded file paths before checking for local files.

Changes:

  • Uses decoded paths for existence checks and data-local-file, while preserving HTML escaping and the original href.
  • Keeps malformed percent-encoded paths unchanged.
  • Adds regression tests for encoded spaces, brackets, quotes, and malformed encoding.
File Description
src/​test/​common/​utils.test.ts Adds decoding, HTML escaping, and fallback regression tests.
src/​common/​utils.ts Decodes permalink paths before local lookup and attribute generation.

Review effort: Balanced

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.

2 participants