echo icon indicating copy to clipboard operation
echo copied to clipboard

Fix `echo.bindData` not binding multiple values when map is used as destination

Open ganigeorgiev opened this issue 2 years ago • 3 comments

When calling echo.Bind(), echo.BindBody(), echo.BindHeaders(), etc. with *map[string]any as destination, currently multiple values of a single entry are being swallowed and only the first value is binded.

Multiple values could be a result from repeatable/array multipart/form-data fields or header with multiple values.

This issue seems to be available in both v4 and v5_alpha.

I've submitted the PR against v5_alpha since it could be a breaking change for v4 in case someone is relying on the current single value bind behavior.

ganigeorgiev avatar Jun 26 '23 11:06 ganigeorgiev

could you add tests were request is multipart/form-data and another one for header binding. to have little bit higher (abstraction)level assurance how this plays along with http package.

aldas avatar Jun 26 '23 11:06 aldas

On second thought, maybe there should be also checks to reflect on the map value to ensure that map[string]string/[]string will not panic in case mismatched values are passed?

ganigeorgiev avatar Jun 26 '23 12:06 ganigeorgiev

I've pushed an update that applies different bind behavior based on the map value type (string, slice, interface) but I'm no longer sure whether the interface{} special handling is a good idea (and it can become even more complicated if we further validate the slice type whether it is string or interface{}).

Feel free to close the PR if you think that it is not clear or ambiguous.

ganigeorgiev avatar Jun 26 '23 13:06 ganigeorgiev

I'm closing this PR because as mentioned above I no longer think that the suggested implementation is the right way to handle this use case.

ganigeorgiev avatar Mar 24 '24 08:03 ganigeorgiev