ansman/validate.js

Numbers that are strings are marked as invalid

Opened this issue · 0 comments

Let's say I have a the following object and validator configuration:

const myObject = {
  age: "24"
};
{
  age: {
    type: "number",
    numericality: {
      greaterThan: 0
    }
  }
}

The configuration will return an error Age must be of type number. The problem is that the documentation states:

Per default strings are coerced to numbers using the + operator.

While this is true, the logic has no chance of being hit - the type check is triggered first and throws an error.