Skip to content

Commit d237f89

Browse files
Fix issue 55 (#56)
* test * fix --------- Co-authored-by: Aleksey Mikhaylov <mikhailov.av@exmo.com>
1 parent 8e44b94 commit d237f89

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

bindform.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,12 @@ func bindAdditionalProperties(additionalProperties reflect.Value, parentStruct r
288288

289289
func marshalFormImpl(v reflect.Value, result url.Values, name string) {
290290
switch v.Kind() {
291-
case reflect.Interface, reflect.Ptr:
291+
case reflect.Ptr:
292+
if v.IsNil() {
293+
break
294+
}
295+
fallthrough
296+
case reflect.Interface:
292297
marshalFormImpl(v.Elem(), result, name)
293298
case reflect.Slice:
294299
for i := 0; i < v.Len(); i++ {

bindform_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ func TestMarshalForm(t *testing.T) {
133133
StructSlice []testSubStruct `json:"struct_slice,omitempty"`
134134
OptInt *int `json:"opt_int,omitempty"`
135135
OptBool *bool `json:"opt_bool,omitempty"`
136+
OptBoolNullable *bool `json:"opt_bool_nullable"`
136137
OptString *string `json:"opt_string,omitempty"`
137138
OptStruct *testSubStruct `json:"opt_struct,omitempty"`
138139
OptStructSlice *[]testSubStruct `json:"opt_struct_slice,omitempty"`
@@ -151,6 +152,7 @@ func TestMarshalForm(t *testing.T) {
151152
},
152153
"opt_int=456": {OptInt: func(v int) *int { return &v }(456)},
153154
"opt_bool=true": {OptBool: func(v bool) *bool { return &v }(true)},
155+
"": {OptBoolNullable: nil},
154156
"opt_string=def": {OptString: func(v string) *string { return &v }("def")},
155157
"opt_struct[int]=456&opt_struct[string]=def": {OptStruct: &testSubStruct{Int: 456, String: "def"}},
156158
"opt_struct_slice[0][int]=123&opt_struct_slice[0][string]=abc&opt_struct_slice[1][int]=456&opt_struct_slice[1][string]=def": {

0 commit comments

Comments
 (0)