Skip to content
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

[Request] truthy/falsy case insensitive #1052

Closed
gangstead opened this issue Dec 1, 2016 · 5 comments
Closed

[Request] truthy/falsy case insensitive #1052

gangstead opened this issue Dec 1, 2016 · 5 comments
Assignees
Labels
bug Bug or defect
Milestone

Comments

@gangstead
Copy link

Context

In the 10.0.0 release notes it is said that the pre 10.0.0 functionality can be achieved with:

Joi.boolean().truthy('true', 'yes', 1, '1').falsy('false', 'no', 0, '0')

This is not quite the same as the old schema as the new implementation with set doesn't use the insensitive flag when checking for set membership

result.value = (this._inner.truthySet.has(value) ? true
where the previous implementation was case insensitive. A closer approximation to the old behavior would be

Joi.boolean().truthy('true', 'True', 'TRUE', 'yes', 'Yes', 'YES', 1, '1').falsy('false', 'False', 'FALSE', 'no', 'No', 'NO', 0, '0')

but still wouldn't cover bizarre capitalization permutations (TRUe) like the previous behavior.

Would you (Joi team) be open to a PR that makes truthy and falsy values entered be case insensitive? I'm willing to do it but want to make sure it fits into the project's roadmap.

  • joi version: 10.0.0
  • used with (hapi, standalone, ...): hapi
@Marsup
Copy link
Collaborator

Marsup commented Dec 1, 2016

I'd say stop accepting drunk users, but I'm ok with a PR :)

@Marsup Marsup added the bug Bug or defect label Dec 1, 2016
@Marsup Marsup self-assigned this Dec 1, 2016
@Marsup
Copy link
Collaborator

Marsup commented Dec 1, 2016

Actually, I think I'll do it, as I think a new method is needed.

@gangstead
Copy link
Author

It wouldn't be a problem but we don't want to break our old APIs that use the old Joi validators. Probably no one would notice 'yes' and 'no' going away but using the strings 'true' and 'false' probably would. We joked that there should be a Joi.booleany() that has the <10.0 boolean behavior.

@Marsup
Copy link
Collaborator

Marsup commented Dec 1, 2016

Free to do so with extensions.

@Marsup Marsup closed this as completed in f96167a Dec 1, 2016
@Marsup Marsup added this to the 10.0.2 milestone Dec 1, 2016
@gangstead
Copy link
Author

Thanks

AdriVanHoudt referenced this issue in hapijs/bell Dec 2, 2016
@lock lock bot locked as resolved and limited conversation to collaborators Jan 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Bug or defect
Projects
None yet
Development

No branches or pull requests

2 participants