-
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
Joi.any().when is not evaluated if empty #332
Comments
You should follow the rules of the bug hunt and open a failing test. The fix is not right but the issue looks valid. |
Sure, I will create the test, sorry for that. I just wonder why you say the fix is not right, I'd love to learn from that. I went through the code, and as long as "undefined" is in the "valid" list, when an empty value will be received it will automatically pass. I saw how any().required is implemented and figured I can use the same method. Logically it makes sense to say that fields with "when" clause must be evaluated on every validation cycle. I tried and saw that my fix didn't break anything, and it actually solved my issue. Thanks in advance. |
Take a look at the commit above. This was a bit more complex. First, normal alternative doesn't require a match by default if the key is missing so the change belonged in the |
Looking at your actual failing test, I am not sure what's the right solution for that one. Basically, you can now (with the fix) make this work by removing |
I see, I'm glad I could make you think :) Thanks for the elaborate explanation and for the workaround! |
Joi.any().when is not evaluated it its value is empty even if the when condition is fulfilled.
For example:
If you use this object to validate {b: true} the returned value will remain {b: true} but it actually should return an error.
The text was updated successfully, but these errors were encountered: