Align excluded_without with its stated multi-field contract - #1621
Open
dylanpulver wants to merge 1 commit into
Open
Align excluded_without with its stated multi-field contract#1621dylanpulver wants to merge 1 commit into
dylanpulver wants to merge 1 commit into
Conversation
excludedWithout passed the whole parameter string to requireCheckFieldKind as a single field name, so excluded_without=A B looked up a field literally named "A B", never found it, and fell back to defaultNotFoundValue=true. The field was therefore excluded unconditionally, whatever A and B held. All seven sibling validators (excluded_with, excluded_with_all, excluded_without_all, required_with, required_with_all, required_without, required_without_all) parse the parameter with parseOneOfParam2 and loop. requiredWithout got exactly this fix in go-playground#1422; its adjacent twin was not swept.
Contributor
|
Thank you for your contribution! |
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
excludedWithoutpasses the whole parameter torequireCheckFieldKindas one field name, soexcluded_without=Field2 Field3looks up a field literally named"Field2 Field3", never finds it, and falls back todefaultNotFoundValue=true. The field is then excluded unconditionally, whatever Field2 and Field3 hold — a silent wrong answer, not an error.Its own doc comment says "when any of the other specified fields are not present", and all seven
excluded_with*/required_with*/required_without*siblings parse withparseOneOfParam2and loop.requiredWithout, directly below it, got exactly this fix in #1422; the adjacent twin was not swept.Measured with Field1 set:
Single-parameter behaviour is unchanged (
parseOneOfParam2("A")→["A"]).Run back to back: upstream fails the new test, the fix passes,
go test ./...is 25/25 ok. A naive variant usingexcluded_without_all's all-absent loop also fails the new test — that case is what separates the two tags.Drafted with Claude Opus 5 (
claude-opus-5); every claim was executed.Make sure that you've checked the boxes below before you submit PR:
@go-playground/validator-maintainers