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); }