fixes GHSA-mgqc-3445-qghq checks standard date fields

This commit is contained in:
plegall
2026-02-17 18:54:20 +01:00
parent b26ca3e08a
commit 0f359f2af5
2 changed files with 40 additions and 0 deletions
+30
View File
@@ -3095,4 +3095,34 @@ function get_container_info()
}
}
/**
* Checks if the provided string is valid for a comparison test with a datetime field in MySQL
*
* Possible values : YYYY-MM-DD HH-MM-SS or YYYY-MM-DD
*
* @since 16.3
* @param string $datetime
* @return bool
*/
function is_valid_mysql_datetime(string $datetime)
{
// first we check the full date+time
$format = 'Y-m-d H:i:s';
$date = DateTime::createFromFormat($format, $datetime);
if ($date and $date->format($format) === $datetime)
{
return true;
}
// in case it fails, let's check with only date and no time
$format = 'Y-m-d';
$date = DateTime::createFromFormat($format, $datetime);
if ($date and $date->format($format) === $datetime)
{
return true;
}
return false;
}
?>