Skip to content

fix(bind): return error for unsupported map value types- #7⁠ - #3236

Closed
its-ernest wants to merge 2 commits into
labstack:masterfrom
its-ernest:fix/bind-unsupported-map-value-types
Closed

its-ernest wants to merge 2 commits into
labstack:masterfrom
its-ernest:fix/bind-unsupported-map-value-types

Conversation

@its-ernest

Copy link
Copy Markdown
Contributor

Summary

Fixes #3235.

bindData silently returned nil for map destinations whose value type is not string, []string or any, leaving the destination untouched while reporting success. It now returns a descriptive error instead.

Behavior change

Binding to an unsupported map value type (for example map[string]int) now returns 400 Bad Request through BindQueryParams / BindPathValues / BindHeaders / form binding, rather than silently succeeding without binding.

Test plan

  • go test ./...
  • Updated TestDefaultBinder_bindDataToMap to assert the error for map[string]int and map[string][]int (with and without a nil map)

Binding to a map whose value type is not string, []string or any
silently returned nil and left the destination untouched. Return a
descriptive error instead.

Fixes #1
Add public API tests for supported map destinations and for map
destinations with unsupported value types via query and header binding.
vishr added a commit that referenced this pull request Nov 20, 2026
Binding path, query, header, or form data into a map whose value type is
not string, []string, or any used to skip silently, and named string
types panicked in SetMapIndex. bindData now returns an error for these
destinations. DefaultBinder.Bind ignores that error when a JSON or XML
body will be decoded into the map, so map[string]int with path params
and a JSON body still binds.

Fixes #3235
Supersedes #3236

Co-authored-by: its-ernest <204517848+its-ernest@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vishr

vishr commented Nov 20, 2026

Copy link
Copy Markdown
Member

Thank you @its-ernest for reporting #3235 and for this fix. Review found that this version returned 400 when a JSON body was bound into a map like map[string]int on a route with path params, and that named value types still panicked. The fix landed in #3238, built on your work, and you are credited as co-author. Closing in favor of that PR.

@vishr vishr closed this Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] bindData silently ignores map destinations with unsupported value types

2 participants