Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

in rule false positive with zero integer value #429

Open
ddegr opened this issue Jun 23, 2021 · 1 comment
Open

in rule false positive with zero integer value #429

ddegr opened this issue Jun 23, 2021 · 1 comment

Comments

@ddegr
Copy link

ddegr commented Jun 23, 2021

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() {
    const validator = new Validator(
      {
        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?

@chantouchsek
Copy link

@ddegr check it out here, it was forked to fix.
chantouchsek/validatorjs#227

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants