-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Chaining string.insensitive() will not convert values with lowercase/uppercase modifiers #1191
Comments
So essentially you want the validation portion to be |
Yes, I would expect them both to work together. The fact that |
So, from looking at Joi primarily as a validator it seems weird to me to expect them both to be respected equally. When validating a string, you're simultaneously saying "I don't care what case it is" and "it must be lowercase". That said, I think there is room for improvement on the coercion step. If the validation rule is |
I agree with you that its a little strange from a validation perspective. But the statement
are not mutually exclusive. The But like you said, this is really just about the conversion, and perhaps we need to look at what happens if the conversion doesn't happen? Does this make any sense if you have schema = Joi.string().valid(['a', 'b', 'c']).insensitive().lowercase();
schema.validate('A', { convert: false })
/// ??? This does seem really strange...because I'm not sure what the behavior should be. |
Like you said
so the current validation behavior matches my personal expectation: Joi.string().insensitive().lowercase().options({convert: false}).validate('Ay No');
// ValidationError: "value" must only contain lowercase characters That's primarily why I could get behind a PR to apply the same idea to the data coercion/conversion. :) |
Hey wait... Joi.string().insensitive().lowercase().validate('Ay No')
// { error: null, value: 'ay no' } It looks like it's already doing the thing. |
Ah, yeah this doesn't work when you specify a whitelist 😄 |
And more to the point, the validation against the whitelist is what is the concern. If you have a whitelist in mixed case ( perhaps dynamically generated ) you may want many things:
|
I just went back and read your original issue, and I apologize for not catching the I think that's actually a different question altogether on whether or not the values provided to |
I think this is actually just a documentation problem.
and paired with
The documentation suggests that lowercase(), uppercase(), trim() and replace() are convert options only, and not validation directives. |
Documentation PRs are always welcome ;) |
Yeah, basically does removing that whole paragraph make it correct? Because each one of those is separately documented. I'll gladly send a PR 👍 |
I think so, yes, since there is a note on the |
I think this is still a bug at the Joi.string().valid(['c', 'b', 'a']).insensitive().lowercase().validate('A', { convert: false })
// { error: null, value: 'A' }
Joi.string().insensitive().lowercase().validate('A', { convert: false })
// { error: ValidationError: "value" must only contain lowercase characters ... |
I'll let others with more experience in managing Joi make the final call, but my first instinct is to say that That being said, I don't have strong feelings about it and could be convinced otherwise :) |
Yeah, I agree with you there @WesTyler. That said, I'd definitely be willing to take a look at a PR to address your concerns @rooftopsparrow. |
Re-qualifying as a bug. |
Just so I'm 100% clear here (sorry this issue kind of went all over). This behavior is wrong: Joi.string().valid(['c', 'b', 'a']).insensitive().lowercase().validate('A', { convert: false })
// { error: null, value: 'A' } and should instead return the validation message from the |
From my perspective yes, it should return Remember |
And to answer about the |
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. |
Context
What are you trying to achieve or the steps to reproduce ?
I thought it was fairly confusing that these options do not work together
Which result you had ?
After validation with
schema
, the value was'A'
After validation with
anotherSchema
, the value was'b'
What did you expect ?
After validation with
schema
, the value should be'a'
After validation with
anotherSchema
, the value should be'B'
Now its fine that there is a workaround to just convert the array to the correct casing and use:
but seems like odd behavior for this to not work with both. I can submit a PR if you agree.
Thanks for Joi!
The text was updated successfully, but these errors were encountered: