Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions interactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,8 +416,9 @@ func literalSegments(template string) int {
// value reports whether the match was segment-for-segment exact; callers should
// prefer an exact match over a wildcard one.
func matchPathTemplate(template, path string) (params map[string]string, matched, exact bool) {
tParts := strings.Split(template, "/")
pParts := strings.Split(path, "/")
// The client builds its URL with url.JoinPath, which drops a trailing slash, so neither side's counts.
tParts := strings.Split(strings.TrimSuffix(template, "/"), "/")
pParts := strings.Split(strings.TrimSuffix(path, "/"), "/")

if len(tParts) > len(pParts) {
return nil, false, false
Expand Down
3 changes: 3 additions & 0 deletions interactions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ func TestMatchPathTemplate(t *testing.T) {
// trailing wildcard param consuming multiple slash-separated segments
{"/package/{path}", "/package/github.com/google/go-cmp/cmp", true, "path", "github.com/google/go-cmp/cmp"},
{"/package/{path}", "/package/single", true, "path", "single"},
// a trailing slash in the spec, which the client's url.JoinPath drops
{"/v7/finance/options/{ticker}/", "/v7/finance/options/ONDS", true, "ticker", "ONDS"},
{"/v7/finance/options/{ticker}", "/v7/finance/options/ONDS/", true, "ticker", "ONDS"},
}

for _, tc := range tests {
Expand Down
Loading