From 5db6b2f65da8f1b02eb042d2d2b182a6a9c945dd Mon Sep 17 00:00:00 2001 From: JasonYH Date: Wed, 13 May 2020 16:05:18 +0800 Subject: [PATCH] Closes swoft-cloud/swoft/issues#1274 --- src/validator/src/Rule/IsBoolRule.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/validator/src/Rule/IsBoolRule.php b/src/validator/src/Rule/IsBoolRule.php index cd0919a95..75b8bf017 100644 --- a/src/validator/src/Rule/IsBoolRule.php +++ b/src/validator/src/Rule/IsBoolRule.php @@ -42,9 +42,10 @@ public function validate(array $data, string $propertyName, $item, $default = nu throw new ValidatorException($message); } - $value = $data[$propertyName]; - if ($value == 'true' || $value == 'false' || is_bool($value)) { - $data[$propertyName] = (bool)$value; + $value = filter_var($data[$propertyName], FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE); + + if (is_bool($value)) { + $data[$propertyName] = $value; return $data; }