poppinss / indicative

Indicative is a simple yet powerful data validator for Node.js and browsers. It makes it so simple to write async validations on nested set of data.
https://indicative.adonisjs.com/
MIT License
417 stars 52 forks source link

validate isn't rejected when passed a string #199

Closed rapodaca closed 6 years ago

rapodaca commented 6 years ago

When a string is passed as the first argument to validate, the promise resolves instead of being rejected. This contrasts with the behavior when an object is passed, which is to be rejected.

This non-intuitive behavior makes it possible for some hard-to-track bugs to creep into code using the library. Is there a good reason to for this dual behavior to be present?

Package version

5.0.5

Node.js and npm version

8.8.1

Sample Code (to reproduce the issue)

// resolves with 'foobar', unexpected behavior
await validate('foobar', {
  foo: 'required'
});

I expect the above to be rejected like the following:

// is rejected with expected array
await validate({ }, {
  foo: 'required'
});
thetutlage commented 6 years ago

Passing a string to a method that accepts an object is not desired. The best we can do is throw a hard exception that an object is required.

thetutlage commented 6 years ago

Closing since no response from the issue reporter and not actionable as well