Skip to content

Fix UTF-8 encoding of MCP resource URI template values - #339846

Merged
Connor Peet (connor4312) merged 2 commits into
microsoft:mainfrom
dhairyajangir:fix/uri-template-unicode
Oct 22, 2026
Merged

Connor Peet (connor4312) merged 2 commits into
microsoft:mainfrom
dhairyajangir:fix/uri-template-unicode

Conversation

@dhairyajangir

Copy link
Copy Markdown
Contributor

Fixes #339843

Non-ASCII MCP resource-template values currently produce percent-encoded UTF-16 code units: café becomes caf%E9, and an emoji becomes two surrogate escapes. Encode valid Unicode strings as UTF-8 while retaining the existing ASCII punctuation escaping. Count prefix lengths by Unicode code point so a supplementary character remains intact. This follows RFC 6570 §3.2.1.

The two added tests cover accented/CJK/supplementary characters, punctuation, and supplementary-character prefixes; all 26 existing tests, including control-character zero-padding, remain unchanged.

Validation:

  • Actual-source targeted transpilation followed by node test/unit/node/index.js --run src/vs/base/test/common/uriTemplate.test.ts: 29 passing (28 URI-template tests plus the runner's error check); the two additions fail before the fix. Node 24.19.0 on Linux.
  • Repository ESLint on both changed files and git diff --check: pass.
  • Independent actual-source checks: 192 Unicode cases pass; 3,120 ASCII scalar and 32 string-composite controls remain unchanged.

No Electron/UI or live MCP-server test was run. Malformed lone-surrogate inputs now throw URIError, as reserved expansion already does; the encoder also string-coerces non-string array elements. Existing reserved-percent and composite-operator behavior is otherwise outside this fix.

AI assistance was used for implementation, testing, and an independent review.

Use UTF-8 percent-encoding and count prefix lengths by Unicode code point. Fixes non-ASCII MCP resource-template values reported in microsoft#339843.
Add regressions for UTF-8 encoding and Unicode code-point prefixes; preserve existing ASCII and control-character tests.
Copilot AI balanced review requested due to automatic review settings October 5, 2026 17:07

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@dhairyajangir

Copy link
Copy Markdown
Contributor Author

Could a maintainer authorize the fork workflows so the repository checks can run? The 29 targeted tests and changed-file ESLint pass locally; the CLA and dependency checks have passed. The reproduction and validation limits are in the PR description.

@connor4312 Connor Peet (connor4312) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

thanks!

@connor4312
Connor Peet (connor4312) merged commit 070abe7 into microsoft:main Oct 22, 2026
35 checks passed
@vs-code-engineering vs-code-engineering Bot added this to the 1.144.0 milestone Oct 22, 2026
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.

MCP resource URI templates incorrectly encode non-ASCII variable values

6 participants