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

Check for optional first before running validator #125

Merged
merged 1 commit into from Jan 29, 2019
Merged

Conversation

SamVerschueren
Copy link
Collaborator

The optional predicate currently has a bug. The bug is that the validator is still executed, even when the value is undefined. This is wrong off course because in case of this use case

ow(undefined, ow.optional.string.minLength(3));

The predicate will do undefined.length which throws a Cannot read property 'length' of 'undefined' (or something).

This PR doesn't do that (performance benefit because it doesn't run all the validators) as it first checks if it's optional and if the value is undefined.

@sindresorhus sindresorhus merged commit 3de78ad into master Jan 29, 2019
@sindresorhus sindresorhus deleted the fix-optional branch January 29, 2019 12:02
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

Successfully merging this pull request may close these issues.

None yet

2 participants