You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
trim() states in it's documentation that it edits the field. Intuitively I expected that edit to be applied before the next step in the schema, such that the .empty('') would receive an empty string since the input consisted only of whitespace.
The correct way to do this ... seems to be to pass /\s+/ to .empty()
constschema=Joi.string().empty(/\s+/).trim();schema.validate(' ');// passes (and value is undefined)
Most of the documentation uses .empty('') though..
Would it break everyone's world if .trim() was applied before other validation.....? Possibly.
At a min. I'd like to see the docs improved to state that
Conversions are applied after validations (or whatever the actual behaviour is)
Maybe an example or 2 that uses that whitespace regex with .empty() in that context
The text was updated successfully, but these errors were encountered:
Because your schema is strictly equivalent to Joi.string().empty(Joi.string().regex(/^\s*$/)), which will fail for the same reason a simple string would fail on an empty string. To make it work you'd need Joi.string().empty(Joi.string().allow('').regex(/^\s*$/)).
I'll check to see if the complexity of supporting this exceeds what I'm willing to support, will report back.
This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.
lockbot
locked as resolved and limited conversation to collaborators
Jan 9, 2020
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Context
What are you trying to achieve or the steps to reproduce ?
Describe your issue here, include schemas and inputs you are validating if needed.
Which result you had ?
"value" is not allowed to be empty
What did you expect ?
Successful validation.
trim() states in it's documentation that it edits the field. Intuitively I expected that edit to be applied before the next step in the schema, such that the .empty('') would receive an empty string since the input consisted only of whitespace.
The correct way to do this ... seems to be to pass /\s+/ to .empty()
Most of the documentation uses .empty('') though..
Would it break everyone's world if .trim() was applied before other validation.....? Possibly.
At a min. I'd like to see the docs improved to state that
The text was updated successfully, but these errors were encountered: