Skip to content

Commit f65aa55

Browse files
committed
MDL-86655 lib: Preserve native booleans in PARAM_BOOL cleaning
Return true/false for boolean inputs instead of 0/1, keeping strict comparisons and schema validation correct. MDL-86655 lib: Preserve native booleans in PARAM_BOOL cleaning Return true/false for boolean inputs instead of 0/1, keeping strict comparisons and schema validation correct.
1 parent 93aa033 commit f65aa55

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

lib/classes/param.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -798,17 +798,19 @@ protected function clean_param_value_sequence(mixed $param): mixed {
798798
* Validation for PARAM_BOOL.
799799
*
800800
* @param mixed $param
801-
* @return mixed
801+
* @return bool
802802
*/
803-
protected function clean_param_value_bool(mixed $param): mixed {
804-
// Convert to 1 or 0.
803+
protected function clean_param_value_bool(mixed $param): bool {
804+
if (is_bool($param)) {
805+
return $param;
806+
}
805807
$tempstr = strtolower((string)$param);
806-
if ($tempstr === 'on' || $tempstr === 'yes' || $tempstr === 'true') {
807-
$param = 1;
808-
} else if ($tempstr === 'off' || $tempstr === 'no' || $tempstr === 'false') {
809-
$param = 0;
808+
if ($tempstr === 'on' || $tempstr === 'yes') {
809+
$param = true;
810+
} else if ($tempstr === 'off' || $tempstr === 'no') {
811+
$param = false;
810812
} else {
811-
$param = empty($param) ? 0 : 1;
813+
$param = empty($param) ? false : true;
812814
}
813815
return $param;
814816
}

0 commit comments

Comments
 (0)