fix: sanitizeInput no longer crashes for arrays
This commit is contained in:
@@ -35,6 +35,13 @@ function validateEmail($email)
|
|||||||
*/
|
*/
|
||||||
function sanitizeInput($input)
|
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');
|
return htmlspecialchars(trim($input), ENT_QUOTES, 'UTF-8');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -422,7 +429,16 @@ function redirect($url)
|
|||||||
*/
|
*/
|
||||||
function post($key, $default = '')
|
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]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user