mirror of
https://github.com/labstack/echo.git
synced 2025-09-16 09:16:29 +02:00
committed by
Vishal Rana
parent
fa80ead5e2
commit
647c0b4ec6
@@ -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)
|
||||
|
@@ -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) {
|
||||
|
Reference in New Issue
Block a user