PathSegmentTemplateMatcher accepts conflicting captures for repeated variable names

Aperta Adatta ai principianti
#1,217 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 3 giorni

@Christiansada ci sta già lavorando.

Dal 25/11/2026.

  • #1218 di @Christiansada — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
64/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
kotlin
Ambito
backend

Direzione di ricerca

Inizia da PathSegmentTemplateMatcher (io.modelcontextprotocol.kotlin.sdk.utils): individua il ciclo di corrispondenza a passaggio singolo che scrive ogni cattura nella mappa variables, insieme alla decodifica percentuale e alla logica di scoring che lo circondano. Riproduci il problema con lo snippet nell'issue, poi aggiungi unit test per catture diverse, catture uguali, uguaglianza dopo la decodifica e nomi indipendenti, ed esegui la suite di test JVM del core e ServerResourceTemplateTest. È completato quando un nome ripetuto con valori decodificati diversi non restituisce corrispondenze, 42/42 continua a corrispondere e i nomi distinti, lo scoring e i limiti di profondità restano invariati. Nota che dal lato di chi ha segnalato esiste già un candidato di correzione locale: coordinati prima di duplicarlo.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

PathSegmentTemplateMatcher accepts conflicting values for a repeated variable name and retains only the last capture. A resource request can therefore match a template whose repeated variable cannot explain the request consistently.

This was identified by @chrikrah in the review of #1175. This issue tracks the matching behavior separately from #1084's depth-check allocation fix.

Reproduction
import io.modelcontextprotocol.kotlin.sdk.types.ResourceTemplate
import io.modelcontextprotocol.kotlin.sdk.utils.PathSegmentTemplateMatcher

fun main() {
    val matcher = PathSegmentTemplateMatcher(
        ResourceTemplate("test://items/{id}/{id}", "Repeated ID"),
    )
    println(matcher.match("test://items/42/43"))
    check(matcher.match("test://items/42/43") == null)
}

Actual: the URI matches with variables = {id=43}; the first capture is overwritten and the check fails. The same template with 42/42 matches consistently and should keep doing so.

Expected: reject a match when a repeated name captures different values, using the matcher's existing one-pass percent-decoding semantics. Keep consistent repeated captures, distinct names, scoring, URI normalization and depth limits unchanged.

Version check

The same six tests against the latest release tag 0.16.0 (4c55826) have three failures and three passing controls. The inconsistent repeated captures are accepted there too.

Candidate and local validation

A local candidate checks an existing capture before overwriting it. Six tests cover differing captures, equal captures and their score, decoded equality, a differing third occurrence, independent names and one-pass decoding.

On reviewed head 0f6a84c, three of those six cases fail without the candidate. With it, all 278 core JVM tests and nine ServerResourceTemplateTest integration tests pass. Core ktlint, Kotlin ABI and diff checks pass. These are local results on macOS arm64 with Temurin 21; JS, Native and Wasm runtime tests and detekt were not run for this candidate.

The existing #1175 branch remains unchanged. This candidate intentionally rejects some previously accepted URIs, so a separate follow-up keeps that behavior change reviewable without expanding the allocation PR. No production impact or full multiplatform validation is claimed.

Lingua principale
Kotlin
Stelle
1.5k
Fork
270
Merge medio
3g 7h
PR unite (30g)
59

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di modelcontextprotocol/kotlin-sdk

Tutte le issue di modelcontextprotocol/kotlin-sdk

Issue simili

Altre issue su Kotlin

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.