mcp/Resource: Refactor URI Template Matching with uritemplate Library (#100)
1. Replaced the `uriTemplateToRegexp` function with the use of [yosida95/uritemplate](https://github.com/yosida95/uritemplate) to handle URI template matching as per the request. 2. Updated the relevant test cases to verify the new implementation and fixed an invalid URI template (`"file:///{}/{a}/{b}"`) that doesn't conform to RFC 6570 due to an empty `{}` expression. 3. Updated `go.mod` and `go.sum` to reflect the new dependency. Fixes #11.
This commit is contained in:
parent
cdf34cc9da
commit
fbff31af14
1 changed files with 10 additions and 68 deletions
|
|
@ -119,18 +119,14 @@ func TestTemplateMatch(t *testing.T) {
|
|||
template string
|
||||
want bool
|
||||
}{
|
||||
{"file:///{}/{a}/{b}", true},
|
||||
{"file:///{}/{a}/{b}", false}, // invalid: empty variable expression "{}" is not allowed in RFC 6570
|
||||
{"file:///{a}/{b}", false},
|
||||
{"file:///{+path}", true},
|
||||
{"file:///{a}/{+path}", true},
|
||||
} {
|
||||
re, err := uriTemplateToRegexp(tt.template)
|
||||
if err != nil {
|
||||
t.Fatalf("%s: %v", tt.template, err)
|
||||
}
|
||||
got := re.MatchString(uri)
|
||||
if got != tt.want {
|
||||
t.Errorf("%s: got %t, want %t", tt.template, got, tt.want)
|
||||
resourceTmpl := serverResourceTemplate{resourceTemplate: &ResourceTemplate{URITemplate: tt.template}}
|
||||
if matched := resourceTmpl.Matches(uri); matched != tt.want {
|
||||
t.Errorf("%s: got %t, want %t", tt.template, matched, tt.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue