Skip to content

Encode supplementary characters in reserved URI template expansion - #1931

Open
pournasserian wants to merge 1 commit into
modelcontextprotocol:mainfrom
pournasserian:feat/csharp-sdk-mcp-issue-a107fa
Open

pournasserian wants to merge 1 commit into
modelcontextprotocol:mainfrom
pournasserian:feat/csharp-sdk-mcp-issue-a107fa

Conversation

@pournasserian

Copy link
Copy Markdown

Fixes #1913

Reserved ({+var}) and fragment ({#var}) expansion in UriTemplate.Encode built a Rune from each UTF-16 char. For a surrogate pair (for example, an emoji), that throws ArgumentOutOfRangeException. On netstandard2.0 it didn't throw, but each half was encoded as U+FFFD. The encoder now encodes the full pair as one UTF-8 scalar.

Tests: added ReservedExpansion_EncodesSupplementaryUnicodeScalar covering {+}, {#} and mixed BMP/supplementary values. It fails without the fix and passes with it on net10.0, net9.0, net8.0 and net472.

Reserved ({+var}) and fragment ({#var}) expansion built a Rune from each
UTF-16 char, which throws for a surrogate half. Encode the full surrogate
pair as one UTF-8 scalar instead.

Fixes modelcontextprotocol#1913

This branch has not been deployed

No deployments
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.

Reserved URI-template expansion throws for supplementary Unicode characters

1 participant