From 29fb331563f503f4890d7b6b3d564381fbc24fa3 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhaylov Date: Thu, 26 Dec 2024 19:57:43 +0300 Subject: [PATCH 1/2] test --- bindform_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bindform_test.go b/bindform_test.go index 9f142f4..92180a7 100644 --- a/bindform_test.go +++ b/bindform_test.go @@ -133,6 +133,7 @@ func TestMarshalForm(t *testing.T) { StructSlice []testSubStruct `json:"struct_slice,omitempty"` OptInt *int `json:"opt_int,omitempty"` OptBool *bool `json:"opt_bool,omitempty"` + OptBoolNullable *bool `json:"opt_bool_nullable"` OptString *string `json:"opt_string,omitempty"` OptStruct *testSubStruct `json:"opt_struct,omitempty"` OptStructSlice *[]testSubStruct `json:"opt_struct_slice,omitempty"` @@ -151,6 +152,7 @@ func TestMarshalForm(t *testing.T) { }, "opt_int=456": {OptInt: func(v int) *int { return &v }(456)}, "opt_bool=true": {OptBool: func(v bool) *bool { return &v }(true)}, + "": {OptBoolNullable: nil}, "opt_string=def": {OptString: func(v string) *string { return &v }("def")}, "opt_struct[int]=456&opt_struct[string]=def": {OptStruct: &testSubStruct{Int: 456, String: "def"}}, "opt_struct_slice[0][int]=123&opt_struct_slice[0][string]=abc&opt_struct_slice[1][int]=456&opt_struct_slice[1][string]=def": { From 9c7815742efea7dbcc4bc1a3f67335fb85cc3579 Mon Sep 17 00:00:00 2001 From: Aleksey Mikhaylov Date: Thu, 26 Dec 2024 19:55:41 +0300 Subject: [PATCH 2/2] fix --- bindform.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/bindform.go b/bindform.go index 31b19d9..121f5d6 100644 --- a/bindform.go +++ b/bindform.go @@ -288,7 +288,12 @@ func bindAdditionalProperties(additionalProperties reflect.Value, parentStruct r func marshalFormImpl(v reflect.Value, result url.Values, name string) { switch v.Kind() { - case reflect.Interface, reflect.Ptr: + case reflect.Ptr: + if v.IsNil() { + break + } + fallthrough + case reflect.Interface: marshalFormImpl(v.Elem(), result, name) case reflect.Slice: for i := 0; i < v.Len(); i++ {