Repository navigation
Check empty strings in array items - #173
Merged
Merged
Conversation
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.
{"ids":["a:1",""]}passed validation for an array whose items haveminLength: 3and a pattern, although "" fails both.A property that wasn't sent is skipped by
omitemptyandruntime.ValidatePattern, which treat "" as absent.An array item or map value is always present, but it got the same treatment, so an empty one slipped through.
What changes
An array item's or map value's validator tags no longer start with
omitempty, so "" is checked againstminLength(Var(item, "min=3")).A nullable item, generated as a pointer, keeps
omitempty, since nil is a null there.Only this generated tag changes; properties are untouched.
New
runtime.ValidateItemPattern()checks the pattern of an array item or map value, including "". Pointer elements and non-strings are skipped as before, and a pattern that accepts "" (e.g. ^[a-z]*$) still lets an empty item through.Generated Validate() methods call it for items and values;
runtime.ValidatePattern()is unchanged for properties.Applies to named array and map types as well as arrays and maps held in a struct.
Output changes only in the Var(...) tag of five examples (omitempty, dropped). In
examples/additional-properties/ex1, two tests asserted that an empty map value passes minLength: 1, one of them named "invalid"; they now expect a validation error.Fixes #170