issue #892 - #1623
Open
BenYang12 wants to merge 2 commits into
Open
Conversation
BenYang12
marked this pull request as draft
September 5, 2026 19:47
BenYang12
marked this pull request as ready for review
September 5, 2026 19:51
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes Or Enhances for issue #892
When a custom type converter returns nil, validation currently fails before a callback registered with
RegisterValidationCtx(..., true)can even inspect the context or accept the value. My change lets nil-enabled callbacks run on the resultingreflect.Invalidvalue, including values returned byValidatorValuerand plain nil inputs.The validation loop checks the nil opt-in for each subsequent validator. Validators without that opt-in still fail for invalid values without being called. Error construction avoids reflection panics and retains nil type/value metadata.
Regression tests cover callback invocation and context propagation, acceptance/rejection, typed and converted nil inputs, pointer converters, AND/OR chains, aliases, omission tags, conditional built-ins, and error metadata.
Validation
Verified commit
369ef5447f99afb020bfa84dbf6907940846fd30:go test -count=1 -race -covermode=atomic ./...passes; main package coverage is 96.9%.golangci-lint runpasses with the CI-pinned v2.13.1: 0 issues.git diff --check upstream/master...HEADpasses; both changed Go files are gofmt-clean.validator.goatdfe35cf8317892133dfe31e36054dcbf36aab604, confirming the missing callback behavior.Unresolved v10 compatibility question
I made this intentionally a draft pending maintainer guidance. The change also allows already nil-enabled built-ins (
required_*,excluded_*, andskip_unless) to run on invalid values. As a result, some converted-nil inputs that previously failed unconditionally now pass when the condition permits absence. Custom nil-enabled callbacks can now receive an invalidreflect.Valueand must handle it safely.@go-playground/validator-maintainers