Skip to content

Commit 83cafdd

Browse files
author
JasonYHZ
authored
Merge pull request #576 from swoft-cloud/fix-IsBoolRule
fix IsBoolRule Type conversion bug
2 parents f563df5 + 5db6b2f commit 83cafdd

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/validator/src/Rule/IsBoolRule.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,10 @@ public function validate(array $data, string $propertyName, $item, $default = nu
4242
throw new ValidatorException($message);
4343
}
4444

45-
$value = $data[$propertyName];
46-
if ($value == 'true' || $value == 'false' || is_bool($value)) {
47-
$data[$propertyName] = (bool)$value;
45+
$value = filter_var($data[$propertyName], FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);
46+
47+
if (is_bool($value)) {
48+
$data[$propertyName] = $value;
4849
return $data;
4950
}
5051

0 commit comments

Comments
 (0)