Skip to content
Open
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
4 changes: 4 additions & 0 deletions lib/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
21 changes: 21 additions & 0 deletions lib/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down