Repository navigation
fix(core): expand RFC 6570 list and multi-variable expressions correctly - #3050
surlymochan wants to merge 1 commit into
Conversation
UriTemplate.expandPart had two gaps against RFC 6570:
- A multi-variable expression returned its raw values joined with ",",
without encoding or the operator prefix. `{x,half,y}` produced
`1024,50%,768` and `{/who,dub}` produced `fred,me/too`.
- Under the `.` and `/` operators a non-exploded list was joined with the
operator separator, so `{.list}` gave `.red.green.blue` instead of
`.red,green,blue`. Only the exploded form uses the operator separator.
Each value of a multi-variable expression is now encoded for the operator,
joined with the operator separator and prefixed once, and a non-exploded
list joins with ",". Exploded lists and single-variable expansion are
unchanged. Tests use the RFC's own examples (3.2.1, 3.2.8, 3.2.9).
🦋 Changeset detectedLatest commit: 6bbf23c 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: |
|
Verified locally. On main the five RFC 6570 examples from the description all fail: |
Summary
UriTemplate.expand()doesn't follow RFC 6570 for multi-variable expressions or non-exploded lists under the.and/operators:{x,half,y}1024,50%,7681024,50%25,768(§3.2.1){/who,dub}fred,me/too/fred/me%2Ftoo(§3.2.9){.who,who}fred,fred.fred.fred(§3.2.8)X{.list}X.red.green.blueX.red,green,blue(§3.2.8){/list}/red/green/blue/red,green,blue(§3.2.9)The multi-variable branch in
expandPartreturned the raw values joined with,, skipping both encoding and the operator prefix, so you could get an unencoded/that changes the path. The.and/cases also joined every list with the operator separator, but RFC 6570 only does that for the exploded (*) form.Change
.or/is joined with,. Exploded lists and single-variable expansion are unchanged.@modelcontextprotocol/core-internal.Testing
packages/core-internal/test/shared/uriTemplate.test.tsuse the RFC's own examples. Three of them fail onmainand pass with this change.packages/core-internal:vitest runpasses 1529/1529, andtypecheckandlintare clean.packages/server:vitest runpasses 577/577.This touches
expandPartonly. #3003 (prefix modifiers) and #2810 (decoding inmatch()) are about other parts ofUriTemplate.