Skip to content

bind: treat an empty header value slice as blank - #3170

Open
SashaMIT wants to merge 1 commit into
labstack:masterfrom
SashaMIT:fix/empty-header-values
Open

SashaMIT wants to merge 1 commit into
labstack:masterfrom
SashaMIT:fix/empty-header-values

Conversation

@SashaMIT

@SashaMIT SashaMIT commented Oct 11, 2026 •

Copy link
Copy Markdown

Fixes #3169.

BindHeaders, and the query and form paths that share bindData, read the first string in a value slice. A key whose slice is nil or empty panics with index out of range [0] with length 0. A normal request line does not create that slice. Header.Set("X-Empty", "") stores []string{""} and already binds. Assigning nil or an empty slice into the header map is what panics.

net/http Header.Get returns "" for a missing key and for an empty slice. Binding now does the same. A struct field stays at its zero value. map[string]string and map[string]any store "". []string{""} is unchanged.

go test -count=1 . passed. With the length checks disabled, TestBindHeadersEmptyValueSlice panics at bind.go with index out of range [0] with length 0.

BindHeaders indexed the first value of a header, query, or form entry.
A nil or empty slice panicked. net/http Header.Get returns an empty
string for that slice, and binding now does the same.
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.

BindHeaders panics on nil or empty header value slices

1 participant