Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[9.x] Added new string versions of true and false to the Boolean validation rule #40041

Closed
wants to merge 1 commit into from
Closed

[9.x] Added new string versions of true and false to the Boolean validation rule #40041

wants to merge 1 commit into from

Conversation

jhouie
Copy link

@jhouie jhouie commented Dec 14, 2021

I created this pull request because the validation of boolean fields did not accept the true and false strings as valid values, which ends up causing confusion in the rule operation.

I didn't create new tests but modified the existing ones to work correctly with the new values.

@GrahamCampbell GrahamCampbell changed the title Added new string versions of true and false to the Boolean validation rule [9.x] Added new string versions of true and false to the Boolean validation rule Dec 14, 2021
@igorgaming
Copy link

igorgaming commented Dec 14, 2021

It works correctly, because php does not perceive the strings 'true' and 'false' as boolean, but '0' and '1' does.
Therefore, the code below will always output 'True'

image

Therefore, this will be unexpected behavior, because we validate the value as boolean, although it will always be true in the case of these strings.

@williamxsp
Copy link

This will also create a lot of breaking changes because if youre passing false or 0 to a database with a column tinyint, it will be store properly but 'false' and 'true' not.

@taylorotwell
Copy link
Member

I don't think I'm going to change this behavior. The accepted values are documented.

@andrey-helldar
Copy link
Contributor

andrey-helldar commented Aug 31, 2022

@igorgaming, just use a boolean value along with a file upload in the same request. Not 1 or 0, namely true or false.

In your example, there is a string comparison for empty presence, not a boolean value.

$value = 'true';

return filter_var($value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);
// true

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants