Skip to content

Unexpected Errors with Strings #827

@ghost

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.invalid

I 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.required

If you'd like, I could do a fix and send over a pull request, assuming this isn't the expected behavior for either case.

Metadata

Metadata

Assignees

Labels

bugBug or defect

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions