-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Description
When a string is purely whitespace (e.g. - " ") and uses string.trim, joi will return an any.invalid error instead of an any.empty error. If the value is just an empty string with no whitespace, it correctly returns any.empty.
var schema = joi.string().trim().required();
schema.validate(""); // any.empty
schema.validate(" "); // any.invalidI imagine it has to do with this line, which doesn't check for an empty string. In an earlier check (here), the empty string is accounted for.
Also, is an any.required error the expected behavior for the following case? I would expect an any.empty, since it should be defaulting to an empty string.
var schema = joi.string().default("").trim().required();
schema.validate(); // any.requiredIf you'd like, I could do a fix and send over a pull request, assuming this isn't the expected behavior for either case.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugBug or defectBug or defect