Updated Smarty to release 2.6.31

This commit is contained in:
azett 2019-12-25 19:01:19 +01:00
parent 97fae60a29
commit 9e8298ec05
2 changed files with 23 additions and 18 deletions

View File

@ -27,7 +27,7 @@
* @author Monte Ohrt <monte at ohrt dot com> * @author Monte Ohrt <monte at ohrt dot com>
* @author Andrei Zmievski <andrei@php.net> * @author Andrei Zmievski <andrei@php.net>
* @package Smarty * @package Smarty
* @version 2.6.30 * @version 2.6.31-dev
*/ */
/* $Id$ */ /* $Id$ */
@ -465,7 +465,7 @@ class Smarty
* *
* @var string * @var string
*/ */
var $_version = '2.6.30'; var $_version = '2.6.31';
/** /**
* current template inclusion depth * current template inclusion depth

View File

@ -18,11 +18,11 @@
* @author Monte Ohrt <monte at ohrt dot com> * @author Monte Ohrt <monte at ohrt dot com>
* *
* @param array $params parameters * @param array $params parameters
* @param Smarty_Internal_Template $template template object * @param Smarty
* *
* @return string|null * @return string|null
*/ */
function smarty_function_math($params, $template) function smarty_function_math($params, &$smarty)
{ {
static $_allowed_funcs = static $_allowed_funcs =
array('int' => true, 'abs' => true, 'ceil' => true, 'cos' => true, 'exp' => true, 'floor' => true, array('int' => true, 'abs' => true, 'ceil' => true, 'cos' => true, 'exp' => true, 'floor' => true,
@ -58,12 +58,28 @@ function smarty_function_math($params, $template)
return; return;
} }
foreach ($params as $key => $val) {
if ($key != "equation" && $key != "format" && $key != "assign") {
// make sure value is not empty
if (strlen($val) == 0) {
trigger_error("math: parameter '{$key}' is empty", E_USER_WARNING);
return;
}
if (!is_numeric($val)) {
trigger_error("math: parameter '{$key}' is not numeric", E_USER_WARNING);
return;
}
}
}
// match all vars in equation, make sure all are passed // match all vars in equation, make sure all are passed
preg_match_all('!(?:0x[a-fA-F0-9]+)|([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)!', $equation, $match); preg_match_all('!(?:0x[a-fA-F0-9]+)|([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)!', $equation, $match);
foreach ($match[ 1 ] as $curr_var) { foreach ($match[ 1 ] as $curr_var) {
if ($curr_var && !isset($params[ $curr_var ]) && !isset($_allowed_funcs[ $curr_var ])) { if ($curr_var && !isset($params[ $curr_var ]) && !isset($_allowed_funcs[ $curr_var ])) {
trigger_error("math: function call $curr_var not allowed", E_USER_WARNING); trigger_error("math: function call '{$curr_var}' not allowed, or missing parameter '{$curr_var}'", E_USER_WARNING);
return; return;
} }
@ -71,17 +87,6 @@ function smarty_function_math($params, $template)
foreach ($params as $key => $val) { foreach ($params as $key => $val) {
if ($key != "equation" && $key != "format" && $key != "assign") { if ($key != "equation" && $key != "format" && $key != "assign") {
// make sure value is not empty
if (strlen($val) == 0) {
trigger_error("math: parameter $key is empty", E_USER_WARNING);
return;
}
if (!is_numeric($val)) {
trigger_error("math: parameter $key: is not numeric", E_USER_WARNING);
return;
}
$equation = preg_replace("/\b$key\b/", " \$params['$key'] ", $equation); $equation = preg_replace("/\b$key\b/", " \$params['$key'] ", $equation);
} }
} }
@ -92,13 +97,13 @@ function smarty_function_math($params, $template)
if (empty($params[ 'assign' ])) { if (empty($params[ 'assign' ])) {
return $smarty_math_result; return $smarty_math_result;
} else { } else {
$template->assign($params[ 'assign' ], $smarty_math_result); $smarty->assign($params[ 'assign' ], $smarty_math_result);
} }
} else { } else {
if (empty($params[ 'assign' ])) { if (empty($params[ 'assign' ])) {
printf($params[ 'format' ], $smarty_math_result); printf($params[ 'format' ], $smarty_math_result);
} else { } else {
$template->assign($params[ 'assign' ], sprintf($params[ 'format' ], $smarty_math_result)); $smarty->assign($params[ 'assign' ], sprintf($params[ 'format' ], $smarty_math_result));
} }
} }
} }