From 2a33f27d7bc8d4a62c4e6ee511d00bbb8c3dda90 Mon Sep 17 00:00:00 2001 From: Harsh Singh <143034341+singhharsh1708@users.noreply.github.com> Date: Fri, 27 Nov 2026 19:22:31 +0530 Subject: [PATCH] fix: validStr gives an empty string for an array instead of a TypeError (#8443) --- tests/php/test_validstr_array.php | 45 +++++++++++++++++++++++++++++++ web/includes/functions.php | 2 +- 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 tests/php/test_validstr_array.php diff --git a/tests/php/test_validstr_array.php b/tests/php/test_validstr_array.php new file mode 100644 index 0000000000..65e433d4d9 --- /dev/null +++ b/tests/php/test_validstr_array.php @@ -0,0 +1,45 @@ +high'), 'high'); +check('null is empty', validStr(null), ''); +check('a number is kept', validStr(5), '5'); +foreach (array('a list' => array('x'), 'a keyed array' => array('k' => 'v'), 'a nested array' => array(array('x')), 'an empty array' => array()) as $label => $value) { + $got = null; + try { + $got = validStr($value); + } catch (Throwable $e) { + $got = get_class($e); + } + check("$label is empty", $got, ''); +} + +echo "\n$passes passed, $failures failed\n"; +exit($failures ? 1 : 0); diff --git a/web/includes/functions.php b/web/includes/functions.php index 91eb14b791..610f662372 100644 --- a/web/includes/functions.php +++ b/web/includes/functions.php @@ -2046,7 +2046,7 @@ function validDevicePath($input) { // For general strings function validStr($input) { - if (is_null($input)) return ''; + if (is_null($input) or is_array($input)) return ''; return strip_tags($input); }