diff options
| author | uwetews <uwe.tews@googlemail.com> | 2016-09-11 00:21:45 +0200 |
|---|---|---|
| committer | uwetews <uwe.tews@googlemail.com> | 2016-09-11 00:21:45 +0200 |
| commit | 7e230713c6f4e067590b371b3fa50cfc97c8421f (patch) | |
| tree | 53474b2c31fbe394e0ed2ab0e1db0923b1e76aad /libs/plugins | |
| parent | 810881c76eec71a737f9a44fa36b837e87cb90a7 (diff) | |
| download | smarty-7e230713c6f4e067590b371b3fa50cfc97c8421f.tar.gz smarty-7e230713c6f4e067590b371b3fa50cfc97c8421f.tar.bz2 smarty-7e230713c6f4e067590b371b3fa50cfc97c8421f.zip | |
- improvement {math} misleading E_NOTICE messages when parameter value = null https://github.com/smarty-php/smarty/issues/288 (reverted from commit 810881c76eec71a737f9a44fa36b837e87cb90a7)
Diffstat (limited to 'libs/plugins')
| -rw-r--r-- | libs/plugins/function.math.php | 29 |
1 files changed, 12 insertions, 17 deletions
diff --git a/libs/plugins/function.math.php b/libs/plugins/function.math.php index fc5db335..655fe728 100644 --- a/libs/plugins/function.math.php +++ b/libs/plugins/function.math.php @@ -58,28 +58,12 @@ function smarty_function_math($params, $template) 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 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) { if ($curr_var && !isset($params[ $curr_var ]) && !isset($_allowed_funcs[ $curr_var ])) { - trigger_error("math: function call '{$curr_var}' not allowed, or missing parameter '{$curr_var}'", E_USER_WARNING); + trigger_error("math: function call $curr_var not allowed", E_USER_WARNING); return; } @@ -87,6 +71,17 @@ function smarty_function_math($params, $template) 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; + } $equation = preg_replace("/\b$key\b/", " \$params['$key'] ", $equation); } } |
