diff --git a/pkg/parsers/parsers.go b/pkg/parsers/parsers.go index db0ada832..65ea7431a 100644 --- a/pkg/parsers/parsers.go +++ b/pkg/parsers/parsers.go @@ -79,7 +79,10 @@ func ParsePath(httpPath string, queryRespMap map[string]gjson.Result) (string, e newPath = append(newPath, value) } - if len(pathParts)%2 == 0 { + // Always append the trailing path segment after the last match. + // With N matches, Split produces N+1 parts; the loop above covers + // indices 0..N-1, so the final part (index N) must be added here. + if len(pathParts) > len(matches) { newPath = append(newPath, pathParts[len(pathParts)-1]) } diff --git a/pkg/parsers/parsers_test.go b/pkg/parsers/parsers_test.go index 360785e09..2b6a80c4f 100644 --- a/pkg/parsers/parsers_test.go +++ b/pkg/parsers/parsers_test.go @@ -120,6 +120,18 @@ func TestParseTwoParam(t *testing.T) { assert.Equal(t, "/v1/charges/char_12345/capture/cust_12345", path) } +func TestParsePathTwoParamsWithTrailing(t *testing.T) { + queryRespMap := map[string]gjson.Result{ + "customer": gjson.Parse(`{"id": "cus_12345"}`), + "bank_account": gjson.Parse(`{"id": "ba_12345"}`), + } + + httpPath := "/v1/customers/${customer:id}/sources/${bank_account:id}/verify" + + path, _ := ParsePath(httpPath, queryRespMap) + assert.Equal(t, "/v1/customers/cus_12345/sources/ba_12345/verify", path) +} + func TestParsePathOneParamWithTrailing(t *testing.T) { queryRespMap := map[string]gjson.Result{ "char_bender": gjson.Parse(`{"id": "char_12345"}`),