diff --git a/interactions.go b/interactions.go index a9da4ace..4c7e43af 100644 --- a/interactions.go +++ b/interactions.go @@ -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 diff --git a/interactions_test.go b/interactions_test.go index 1b0d9b8b..d972f557 100644 --- a/interactions_test.go +++ b/interactions_test.go @@ -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 {