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
2 changes: 1 addition & 1 deletion bindparam.go
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ func BindQueryParameterWithOptions(style string, explode bool, required bool, pa
} else {
err = bindSplitPartsToDestinationArray(parts, output)
}
case reflect.Struct:
case reflect.Struct, reflect.Map:
// Some struct types (e.g. types.Date, time.Time) are scalar values
// that should be bound from a single string, not decomposed as
// key-value objects. Detect these via the Binder and
Expand Down
15 changes: 15 additions & 0 deletions bindparam_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,21 @@ func TestBindQueryParameter(t *testing.T) {
assert.Equal(t, types.Date{Time: time.Date(2023, 6, 15, 0, 0, 0, 0, time.UTC)}, *params.StartDate)
})

t.Run("map_form_no_explode_optional", func(t *testing.T) {
want := map[string]string{
"foo": "bar",
"bim": "baz",
}
queryParams := url.Values{
"tags": {"foo,bar,bim,baz"},
}
var got map[string]string
err := BindQueryParameter("form", false, false, "tags", queryParams, &got)
assert.NoError(t, err)
require.NotNil(t, got)
assert.Equal(t, want, got)
})

t.Run("optional", func(t *testing.T) {
queryParams := url.Values{
"time": {"2020-12-09T16:09:53+00:00"},
Expand Down