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
We're using .notEmpty() to validate an incoming request body. After upgrading major version from 6 to 7, our unit tests started to fail. Turns out v7 .notEmpty() does not return a validation error for an empty array.
I do not see this in the breaking changes, unless it's part of some of the other points described there
edit: after looking through the docs, it seems .notEmpty() should have been used for strings. However I think the changed behaviour is still unexpected?
brianweet
changed the title
Different behaviour v6/v7 using .notEmpty() to check empty array
Unexpected change in behaviour v6/v7 for .notEmpty()
Sep 12, 2023
I'm guessing this is an unexpected regression from fixing #791.
Basically, the new behaviour for standard validators is: if you have an array, then every item in the array should comply with the validator.
In the case of there being no items, then it means essentially every item is complying in not being empty...
I think that changing isEmpty() to check the array's length might make sense.
Describe the bug
We're using
.notEmpty()
to validate an incoming request body. After upgrading major version from 6 to 7, our unit tests started to fail. Turns out v7.notEmpty()
does not return a validation error for an empty array.I do not see this in the breaking changes, unless it's part of some of the other points described there
edit: after looking through the docs, it seems
.notEmpty()
should have been used for strings. However I think the changed behaviour is still unexpected?To Reproduce
Here you can see the different results:
Expected behavior
v6 and v7 to have similar behaviour
Current behavior
v7 does not return validation error for empty array
Environment:
The text was updated successfully, but these errors were encountered: