fix: sanitizeInput no longer crashes for arrays

This commit is contained in:
2025-12-09 14:07:00 +01:00
parent 213be99965
commit 41b903cd00

View File

@@ -35,6 +35,13 @@ function validateEmail($email)
*/
function sanitizeInput($input)
{
// Handle non-string values
if (is_array($input)) {
return array_map('sanitizeInput', $input);
}
if (!is_string($input)) {
$input = (string)$input;
}
return htmlspecialchars(trim($input), ENT_QUOTES, 'UTF-8');
}
@@ -422,7 +429,16 @@ function redirect($url)
*/
function post($key, $default = '')
{
return isset($_POST[$key]) ? sanitizeInput($_POST[$key]) : $default;
if (!isset($_POST[$key])) {
return $default;
}
// If the value is an array, return the first element or default
if (is_array($_POST[$key])) {
return !empty($_POST[$key]) ? sanitizeInput($_POST[$key][0]) : $default;
}
return sanitizeInput($_POST[$key]);
}
/**