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.
The
optional
predicate currently has a bug. The bug is that the validator is still executed, even when the value isundefined
. This is wrong off course because in case of this use caseThe predicate will do
undefined.length
which throws aCannot 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 thevalue
isundefined
.