Skip to content
Myr

fix bug, return err when failed binding bool (#1350)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* fix bug, return err when failed binding bool * add test, return err when failed binding bool

authored by chainhelen · committed by Bo-Yi Wu · parent 995fa8e · Browse files · 2 files+24 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+24 added−1 removed

  • other:+24 added−1 removed

2 files+24 added−1 removed

modified:binding/binding_test.go+23 added
89 unmodified lines
90 // Unknown type: not support map91 SliceMapFoo []map[string]interface{} `form:"slice_map_foo"`92}9394type FooStructForBoolType struct {95 BoolFoo bool `form:"bool_foo"`96}9798type FooBarStructForIntType struct {99 IntFoo int `form:"int_foo"`100 IntBar int `form:"int_bar" binding:"required"`101}
350 unmodified lines
452 "/?map_foo=", "/?bar2=foo",453 "map_foo=unused", "")454}455456func TestBindingQueryBoolFail(t *testing.T) {457 testQueryBindingBoolFail(t, "GET",458 "/?bool_foo=fasl", "/?bar2=foo",459 "bool_foo=unused", "")460}461462func TestBindingXML(t *testing.T) {463 testBodyBinding(t,464 XML, "xml",465 "/", "/",
606 unmodified lines
1072 err := b.Bind(req, &obj)1073 assert.Error(t, err)1074}10751076func testQueryBindingBoolFail(t *testing.T, method, path, badPath, body, badBody string) {1077 b := Query1078 assert.Equal(t, "query", b.Name())10791080 obj := FooStructForBoolType{}1081 req := requestWithBody(method, path, body)1082 if method == "POST" {1083 req.Header.Add("Content-Type", MIMEPOSTForm)1084 }1085 err := b.Bind(req, &obj)1086 assert.Error(t, err)1087}10881089func testBodyBinding(t *testing.T, b Binding, name, path, badPath, body, badBody string) {1090 assert.Equal(t, name, b.Name())10911092 obj := FooStruct{}
125 unmodified lines
modified:binding/form_mapping.go+1 added-1 removed
159 unmodified lines
160 boolVal, err := strconv.ParseBool(val)161 if err == nil {162 field.SetBool(boolVal)163 }164 return nil164 return err165}166167func setFloatField(val string, bitSize int, field reflect.Value) error {168 if val == "" {
41 unmodified lines