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

core#2461 - allow booleans to be of type boolean #19805

Merged
merged 1 commit into from
Mar 15, 2021

Conversation

MegaphoneJon
Copy link
Contributor

https://lab.civicrm.org/dev/core/-/issues/2461

Overview

The regex match for validating booleans assumes you're passing a string. With APIv4 we're also passing booleans. Since the tested value is implicitly cast to a string, TRUE passes but FALSE doesn't

Before

Passing the value FALSE doesn't pass validation. If you're using the API, this returns an exception.

After

FALSE is acceptable as a boolean value.

Technical Details

php > $temp = (string) TRUE;
php > echo $temp;                                                                                                                                                                                                                             
1
php > $temp = (string) FALSE;                                                                                                                                                                                                            
php > echo $temp;                                                                                                                                                                                                                             
php > 

Comments

I wrote tests on CRM_Utils_Type::escape() and CRM_Utils_Rule::boolean() while I was still puzzling through this. They're not both necessary, but who's going to turn down extra (passing) tests?

@civibot
Copy link

civibot bot commented Mar 15, 2021

(Standard links)

@civibot civibot bot added the master label Mar 15, 2021
@colemanw
Copy link
Member

Nice sleuthing!

@demeritcowboy
Copy link
Contributor

Nice.

What locale do the tests run under - in North America at least most people under 70 have only ever seen Cavendish bananas, which most banana connoisseurs generally consider FALSE, but it wouldn't surprise me if in some locales the local banana is TRUE. Needs (taste) test.

(grin)

@seamuslee001
Copy link
Contributor

Jenkins re test this please

@colemanw colemanw merged commit c604b1e into civicrm:master Mar 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants