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
{{ message }}
Repository navigation
in rule false positive with zero integer value #429
I've bumped to the odd behavior of the in rule. It throws ok when it should have not to.
My validating object must have status field. The status value must be in the array of possible values [1, 2, 3, 4].
So validation rule is defined like that: status: 'required|in:1,2,3,4'.
When status is 0 validator says everything is fine but mustn't as there is no 0 int the giving possible values.
I also tried to rewrite rule. Somehow like that status: [ 'required', { in: [1, 2, 3, 4] }] and got the same wrong result.
Then I cloned validatorjs and added test case to the spec/in-rule.js file.
it("should fail when 0 (zero) is not in giving arra",function(){constvalidator=newValidator({quantity: 0},{quantity: "in:1,2"});expect(validator.passes()).to.be.false;expect(validator.fails()).to.be.true;});
So my test case doesn't pass. Am I doing something wrong? Or this is bug?
Activity
chantouchsek commentedon Jul 6, 2022
@ddegr check it out here, it was forked to fix.
chantouchsek/validatorjs#227