From f9a714b8a5a20c03b4121d81986624e42a656763 Mon Sep 17 00:00:00 2001 From: Jon Goldberg Date: Thu, 9 Jun 2022 16:22:31 -0400 Subject: [PATCH] improve Boolean validation and normalization --- CHANGELOG.md | 2 ++ Civi/FormProcessor/Type/BooleanType.php | 18 ++++-------------- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f5be333..e819d3b 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ Version 1.39-dev ============ +* Fix validation and normalization issues with boolean inputs. + Version 1.38 ============ diff --git a/Civi/FormProcessor/Type/BooleanType.php b/Civi/FormProcessor/Type/BooleanType.php index e36bba8..31d22cd 100644 --- a/Civi/FormProcessor/Type/BooleanType.php +++ b/Civi/FormProcessor/Type/BooleanType.php @@ -29,15 +29,7 @@ class BooleanType extends AbstractType { } public function validateValue($value, $allValues = []) { - $returnAs = $this->configuration->get('return_as') ?? 'boolean'; - $type = 'Boolean'; - if ($returnAs === 'integer') { - $type = 'Integer'; - } - if (\CRM_Utils_Type::validate($value, $type, FALSE) === NULL) { - return FALSE; - } - return TRUE; + return \CRM_Utils_Rule::boolean($value); } /** @@ -65,14 +57,12 @@ class BooleanType extends AbstractType { $result = $value; } else { - switch ((string) $value) { + switch (strtolower((string) $value)) { case '1'; - case 'True': case 'true': - case 'Yes': case 'yes': - case 'Y': - case 'T': + case 'y': + case 't': $result = TRUE; break; -- GitLab