Skip to content

Check empty strings in array items - #173

Merged
cubahno merged 1 commit into
mainfrom
ig/fix-arr-empty-str
Oct 14, 2026
Merged

cubahno merged 1 commit into
mainfrom
ig/fix-arr-empty-str

Conversation

@cubahno

@cubahno cubahno commented Oct 14, 2026

Copy link
Copy Markdown
Collaborator

{"ids":["a:1",""]} passed validation for an array whose items have minLength: 3 and a pattern, although "" fails both.
A property that wasn't sent is skipped by omitempty and runtime.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 against minLength (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

@cubahno
cubahno marked this pull request as ready for review October 14, 2026 09:10
@cubahno
cubahno merged commit a10b4d0 into main Oct 14, 2026
3 checks passed
@cubahno
cubahno deleted the ig/fix-arr-empty-str branch October 14, 2026 09:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Empty strings bypass pattern and minLength on array items

1 participant