You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When validations fields I noticed that array had a different behavior than other values.
If an empty array is given no validation is run and the field is considered valid even if we're not expecting an array value.
I think this line in standard-validation.ts producing this behavior.
In the RunKit I'm expecting only count1 and count6 to be valid because the doc states if value is an array then each element of an array is validated.
It seems a bit weird that all types fails except arrays which means most validators needs an extra not().isArray() to prevent unexpected values in following middlewares.
Current behavior
In the RunKit , count1, count5 and count6 are valid.
Environment:
Express-validator version: 7.0.1
Express version: 4.18.2
Node.js version: 18.16.1
PS:
I tagged this as a bug but maybe it should be a feature request?
An option or a config to add that enable or disable the use of array values?
The text was updated successfully, but these errors were encountered:
Understandable. The behaviour today is like Array#some()/Array#every(), in that they respectively return false/true for empty arrays, no matter what the predicate is.
An option or a config to add that enable or disable the use of array values?
This would be the most pragmatic approach. Changing the behaviour at all without such will be a breaking change.
I don't know how that'd look, but I'd be open for some brainstorming (before anyone jumps into coding).
I'm willing to help but I don't have any experience in open-source so I'm not sure how that brainstorming would go? 😄
I might have an idea or 2 I'll try to test them when I have the time to make sure they work.
Describe the bug
Hi!
When validations fields I noticed that array had a different behavior than other values.
If an empty array is given no validation is run and the field is considered valid even if we're not expecting an array value.
I think this line in standard-validation.ts producing this behavior.
To Reproduce
Here's a RunKit reproducing the error.
Expected behavior
In the RunKit I'm expecting only
count1
andcount6
to be valid because the doc states if value is an array then each element of an array is validated.It seems a bit weird that all types fails except arrays which means most validators needs an extra
not().isArray()
to prevent unexpected values in following middlewares.Current behavior
In the RunKit ,
count1
,count5
andcount6
are valid.Environment:
PS:
I tagged this as a bug but maybe it should be a feature request?
An option or a config to add that enable or disable the use of array values?
The text was updated successfully, but these errors were encountered: