From bfd7903230cc6ad81e3678a87f6e7f1352a3c044 Mon Sep 17 00:00:00 2001 From: Sam Harrison Date: Tue, 7 Jul 2026 16:26:53 -0500 Subject: [PATCH] fix: BuildPath drops string placeholder values, sending requests to the wrong URL --- lib/query.go | 4 ++++ lib/query_test.go | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/lib/query.go b/lib/query.go index 9cb07faf..d37b0d65 100644 --- a/lib/query.go +++ b/lib/query.go @@ -46,6 +46,8 @@ func BuildPath(resourcePath string, values interface{}) (string, error) { var exists bool if m, ok := values.(map[string]interface{}); ok { value, exists = m[placeholder] + } else if m, ok := values.(map[string]string); ok { + value, exists = m[placeholder] } else if pathValue, err := findTag(values, "path", placeholder); err == nil { exists = true value = pathValue @@ -74,6 +76,8 @@ func BuildPath(resourcePath string, values interface{}) (string, error) { if err != nil { return "", err } + } else { + stringValue = url.PathEscape(v) } default: stringValue = fmt.Sprintf("%v", v) diff --git a/lib/query_test.go b/lib/query_test.go index 6e425898..8e00bfc0 100644 --- a/lib/query_test.go +++ b/lib/query_test.go @@ -106,6 +106,27 @@ func TestBuildPath(t *testing.T) { "root/{path}", map[string]interface{}{"path": "a/my-path"}}, }, + { + name: "given a map of strings", + want: "root/a/my-path", + args: args{ + "root/{path}", + map[string]string{"path": "a/my-path"}}, + }, + { + name: "given a map of strings with escaping", + want: "root/a%20file%20name.text", + args: args{ + "root/{path}", + map[string]string{"path": "a file name.text"}}, + }, + { + name: "non-path string placeholder", + want: "users/bob%20smith", + args: args{ + "users/{name}", + map[string]interface{}{"name": "bob smith"}}, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {