Repository navigation
Zero-pad percent-encoding for code points below 0x10 in UriTemplate - #323012
Merged
Martin Aeschlimann (aeschli) merged 2 commits intoJul 3, 2026
Merged
Martin Aeschlimann (aeschli) merged 2 commits into
Martin Aeschlimann (aeschli) merged 2 commits into
Conversation
pctEncode emitted '%' + chr.toString(16) without padding, so a code point < 0x10 produced a single-digit escape (e.g. tab -> %9, newline -> %0A becomes %A, CR -> %D) instead of the RFC 3986/6570 two-digit form. The result is a malformed URI that decodeURIComponent rejects with "URI malformed". UriTemplate is used to resolve MCP and agent resource URIs, where a variable value containing a control character would yield a broken URL. Zero-pad to two hex digits with padStart(2, '0'); this is a no-op for code points >= 0x10, so existing escapes (%20, %21, ...) are unchanged. Adds a regression test.
Martin Aeschlimann (aeschli)
enabled auto-merge (squash)
July 2, 2026 08:41
Martin Aeschlimann (aeschli)
approved these changes
Jul 2, 2026
Dmitriy Vasyura (dmitrivMS)
approved these changes
Jul 2, 2026
Sandeep Somavarapu (sandy081)
approved these changes
Jul 2, 2026
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Problem
pctEncodeinsrc/vs/base/common/uriTemplate.tsbuilds escapes without zero-padding:For any code point
< 0x10,toString(16)yields a single hex digit, so the function emits a one-digit escape instead of the RFC 3986 / RFC 6570 mandated two-digit form:%9%09%A%0A%D%0D%7%07The result is a malformed URI;
decodeURIComponentrejects it withURI malformed.UriTemplateresolves MCP and agent resource URIs (e.g.src/vs/workbench/contrib/mcp/,src/vs/platform/agentHost/), so a variable value containing a control character produces a broken URL.Reproduction
Running the real
UriTemplate(transpiled):Fix
Zero-pad to two hex digits:
padStartis a no-op for code points>= 0x10, so existing escapes (%20,%21,%3B, …) are unchanged — verified against the existing test expectations.Test
Adds a regression test in
src/vs/base/test/common/uriTemplate.test.tsasserting{x}with'a\tb','\n','\r'resolve toa%09b,%0A,%0D.