Repository navigation
fix(core-internal): support RFC 6570 prefix modifiers in UriTemplate (#3000) - #3003
MokuLakshithReddy wants to merge 2 commits into
Conversation
🦋 Changeset detectedLatest commit: 2e8e0c9 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@modelcontextprotocol/client
@modelcontextprotocol/codemod
@modelcontextprotocol/core
@modelcontextprotocol/server
@modelcontextprotocol/server-legacy
@modelcontextprotocol/express
@modelcontextprotocol/fastify
@modelcontextprotocol/hono
@modelcontextprotocol/node
commit: |
koriyoshi2041
left a comment
There was a problem hiding this comment.
The valid Unicode path looks good, but malformed prefix specs are now silently reinterpreted as valid variable names. RFC 6570 defines max-length as [1-9][0-9]{0,3} and makes prefix/explode mutually exclusive. At this head I get:
{name:0} -> abcdef
{name:10000} -> abcdef
{name:abc} -> abcdef
{name:3*} -> abc
All four also report variableNames === ['name']. Before this change they did not resolve name, so this broadens invalid templates into successful expansions. Could parseVarSpec accept only :[1-9][0-9]{0,3} and reject (or preserve the old unresolved behavior for) malformed/combined modifiers? Focused regression cases for :0, five digits, non-digits, and :N* would pin the boundary.
…utual exclusivity
|
@koriyoshi2041 Thank you for the detailed review! I have updated the implementation to address this:
|
|
Confirmed on |
Motivation and Context
Fixes #3000
The SDK's
UriTemplatepreviously treated an RFC 6570 prefix modifier (:N) as part of the variable name becausegetNames()stripped*but retained:N. As a result:template.variableNamesreturned["name:3"]instead of["name"].template.expand({ name: "abcdef" })looked forvariables["name:3"]and dropped scalar values from the expanded URI.template.match()looked for an argument named"name:3".Description of Changes
parseVarSpec()inUriTemplateto separate the variable name, explode modifier (*), and prefix modifier (:N).namesandvariableNamesnow preserve the clean variable name (["name"]).applyPrefix()to truncate scalar values to the specified prefix length using code point spreading ([...value].slice(0, prefix).join('')), ensuring correct handling of multi-byte and supplementary Unicode characters before percent-encoding.partToRegExpto use clean variable names when generating matching regexes.packages/core-internal/test/shared/uriTemplate.test.tscovering ASCII, non-ASCII Unicode, supplementary characters, prefixes longer than values, missing variables, array values, and.match()..changeset/uri-template-prefix-modifiers.md.How Has This Been Tested?
packages/core-internal/test/shared/uriTemplate.test.tscovering all prefix modifier behaviors; all 55 tests pass.