1
0
mirror of https://github.com/labstack/echo.git synced 2025-09-16 09:16:29 +02:00

fix panic in form binding. #577 (#579)

This commit is contained in:
Oleg Lobanov
2016-06-23 19:40:14 +05:00
committed by Vishal Rana
parent fa80ead5e2
commit 647c0b4ec6
2 changed files with 12 additions and 0 deletions

View File

@@ -48,6 +48,10 @@ func (b *binder) bindForm(ptr interface{}, form map[string][]string) error {
typ := reflect.TypeOf(ptr).Elem()
val := reflect.ValueOf(ptr).Elem()
if typ.Kind() != reflect.Struct {
return errors.New("binding element must be a struct")
}
for i := 0; i < typ.NumField(); i++ {
typeField := typ.Field(i)
structField := val.Field(i)

View File

@@ -68,6 +68,14 @@ func TestBinderXML(t *testing.T) {
func TestBinderForm(t *testing.T) {
testBinderOkay(t, strings.NewReader(userForm), MIMEApplicationForm)
e := New()
req := test.NewRequest(POST, "/", strings.NewReader(userForm))
rec := test.NewResponseRecorder()
c := e.NewContext(req, rec)
req.Header().Set(HeaderContentType, MIMEApplicationForm)
var obj = make([]struct{ Field string }, 0)
err := c.Bind(&obj)
assert.Error(t, err)
}
func TestBinderMultipartForm(t *testing.T) {