Commit 2f19cb5
committed
Match URI template literals literally in ResourceTemplate.matches
The template-to-regex conversion only substituted the `{param}` braces and
left the surrounding literal text unescaped, so any regex metacharacter in a
template (`.`, `+`, `(`, ...) was interpreted as a pattern rather than a
literal. A template like `resource://a.b+c/{id}` would also match
`resource://aXbYc/...`.
Escape the template with `re.escape` before substituting placeholders so
literal characters match literally; only `{param}` segments become capture
groups.1 parent e9cd169 commit 2f19cb5
2 files changed
Lines changed: 24 additions & 2 deletions
File tree
- src/mcp/server/mcpserver/resources
- tests/server/mcpserver/resources
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
93 | 93 | | |
94 | 94 | | |
95 | 95 | | |
96 | | - | |
97 | | - | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
98 | 100 | | |
99 | 101 | | |
100 | 102 | | |
| |||
Lines changed: 20 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
331 | 331 | | |
332 | 332 | | |
333 | 333 | | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
0 commit comments