function.math bugfix
| From: | Mirko Buffoni | Date: | Mon, 12 Apr 2004 17:20:22 +0000 |
| Subject: | function.math bugfix | ||
| Groups: | php.smarty.general | ||
| Request: | Send a blank email to php-smarty-general+get-11268@lists.php.net to get a copy of this message | ||
Hi friends,
I came across a bug in function math plugin:
...
foreach($params as $key => $val) {
if ($key != "equation" && $key != "format" && $key != "assign") {
// make sure value is not empty
if (strlen($val)==0) {
$smarty->trigger_error("math: parameter $key is empty");
return;
}
if (!is_numeric($val)) {
$smarty->trigger_error("math: parameter $key: is not numeric");
return;
}
$equation = preg_replace("/\b$key\b/",$val, $equation);
}
}
...
Change to:
$equation = preg_replace("/\b$key\b/",preg_replace("!^([\-]?)[0]+([0-9])!","\\1\\2",$val), $equation);
I had 0-padded numbers (can be float too).
Everything it's ok but not 08 and 09 which are considered octal (i think) and
converted to 0.
So an equation like "x+1" leads to 08+1 => 1, and 09+1 => 1.
The change fixes this situation.
Mirko