You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When calling context Bind(...) with a map which has non interface or non assignable value type, a panic is triggered. Even though this is a rare case, and can be worked around using a different map type, or using BindBody, we should not have panics in echo. This looks like it has been the behavior since 2019 or so based on git blame.
func (b *DefaultBinder) bindData(destination interface{}, data map[string][]string, tag string) error {
...
// Map
if typ.Kind() == reflect.Map {
for k, v := range data {
val.SetMapIndex(reflect.ValueOf(k), reflect.ValueOf(v[0]))
}
return nil
}
...
I couldn't find an issue for this elsewhere.
Expected behaviour
Assignable values are bound. Unassignable values are ignored.
Actual behaviour
It panics!
For example:
panic: reflect.Value.SetMapIndex: value of type string is not assignable to type int
Steps to reproduce
See the code below. Call Bind() with a map[string]int and some string query or path parameter available in the context.
This seems to be old unresolved problem. I think we can make it work so binding to map[string]string and map[string][]string works. As the source for the values we are binding is Path params, Headers, Query params, Form params and all of these are string values. For all other map cases we should error out or skip in case of source being "param/query/header/form".
Issue Description
When calling context
Bind(...)
with a map which has non interface or non assignable value type, a panic is triggered. Even though this is a rare case, and can be worked around using a different map type, or usingBindBody
, we should not have panics in echo. This looks like it has been the behavior since 2019 or so based on git blame.This comes down to the reflect assignment here:
echo/bind.go
Line 137 in 584cb85
I couldn't find an issue for this elsewhere.
Expected behaviour
Assignable values are bound. Unassignable values are ignored.
Actual behaviour
It panics!
For example:
Steps to reproduce
See the code below. Call Bind() with a map[string]int and some string query or path parameter available in the context.
Working code to debug
Version/commit
github.com/labstack/echo/v4 v4.11.3
The text was updated successfully, but these errors were encountered: