Skip to content

fix(validate): handle nil containment inputs - #356

Merged
inhere merged 1 commit into
gookit:masterfrom
awais-ur-rehman:feat/nil-contains-values
Nov 1, 2026
Merged

inhere merged 1 commit into
gookit:masterfrom
awais-ur-rehman:feat/nil-contains-values

Conversation

@awais-ur-rehman

Copy link
Copy Markdown
Contributor

Summary

Contains(nil, "x") and NotContains(nil, "x") panic because includeElement calls Type() on an invalid reflected value before installing its recovery handler. Other unsupported container types already return false for both validators.

Check for an invalid reflected container first and return the existing unsupported-input result. Add coverage for nil input, unsupported scalars, typed nil slices/maps, matching/missing elements, nil elements and substrings.

Testing

Validation with Go 1.26.10: go test -race ./..., go vet ./... and go build ./... passed. The regression panics before the fix. Strict golangci-lint 2.15.0 reports the same 66 existing findings on the base and fixed versions, with no new findings.

Manual check: both containment validators should return false for a nil container without panicking; a typed nil slice remains a valid empty container, so NotContains([]string(nil), "x") should return true.

Prepared with Codex assistance for reproduction, implementation and tests.

Breaking Changes

None.

@inhere
inhere merged commit ed93745 into gookit:master Nov 1, 2026
1 check passed
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.

2 participants