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

Undefined is always valid regardless of type #35

Closed
cmawhorter opened this issue Jun 9, 2017 · 2 comments
Closed

Undefined is always valid regardless of type #35

cmawhorter opened this issue Jun 9, 2017 · 2 comments

Comments

@cmawhorter
Copy link

All types are incorrectly reporting undefined as valid. Array is the exception because of #33

Enjoi({ type: 'string' }).validate(undefined, console.log.bind(console, 'string'));
Enjoi({ type: 'array' }).validate(undefined, console.log.bind(console, 'array'));
Enjoi({ type: 'boolean' }).validate(undefined, console.log.bind(console, 'boolean'));
Enjoi({ type: 'number' }).validate(undefined, console.log.bind(console, 'number'));
Enjoi({ type: 'integer' }).validate(undefined, console.log.bind(console, 'integer'));
Enjoi({ type: 'object' }).validate(undefined, console.log.bind(console, 'object'));
Enjoi({ type: 'string' }).validate(undefined, console.log.bind(console, 'string'));

No ValidationError for any of those and the value returned is undefined.

(Sorry for the deluge!)

@tlivings
Copy link
Owner

These should fail against null, but don't because undefined means there is nothing to validate against. It will fail properly if you set keys as required and pass undefined.

I see this behavior in json schema validation as well.

That's not a final answer but first thoughts.

@tlivings
Copy link
Owner

At the end of this day, this behavior is based on Joi. These properties are not necessarily required, but Joi passes validation because they are not marked as required. I don't think there is anything to fix here.

@tlivings tlivings closed this as completed Jan 9, 2018
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