Fix SimpleTemplate TypeError with array handling
- Fix htmlspecialchars() receiving arrays instead of strings - Add proper type checking for string, array, and other types - Convert arrays to JSON for safe template rendering - Remove unused German and French language files
This commit is contained in:
@@ -103,11 +103,19 @@ class SimpleTemplate {
|
||||
foreach ($this->data as $key => $value) {
|
||||
// Handle triple braces for unescaped HTML content
|
||||
if (strpos($template, '{{{' . $key . '}}}') !== false) {
|
||||
$template = str_replace('{{{' . $key . '}}}', $value, $template);
|
||||
$template = str_replace('{{{' . $key . '}}}', is_string($value) ? $value : print_r($value, true), $template);
|
||||
}
|
||||
// Handle double braces for escaped content
|
||||
elseif (strpos($template, '{{' . $key . '}}') !== false) {
|
||||
$template = str_replace('{{' . $key . '}}', htmlspecialchars($value, ENT_QUOTES, 'UTF-8'), $template);
|
||||
if (is_string($value)) {
|
||||
$template = str_replace('{{' . $key . '}}', htmlspecialchars($value, ENT_QUOTES, 'UTF-8'), $template);
|
||||
} elseif (is_array($value)) {
|
||||
// For arrays, convert to JSON string for display
|
||||
$template = str_replace('{{' . $key . '}}', htmlspecialchars(json_encode($value), ENT_QUOTES, 'UTF-8'), $template);
|
||||
} else {
|
||||
// Convert other types to string
|
||||
$template = str_replace('{{' . $key . '}}', htmlspecialchars((string)$value, ENT_QUOTES, 'UTF-8'), $template);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $template;
|
||||
|
||||
Reference in New Issue
Block a user