Undefined variable detection in price parser

This commit is contained in:
Ion Agorria 2016-02-24 18:56:59 +01:00 committed by Ion
parent e528a82051
commit aa0b811f73
2 changed files with 15 additions and 1 deletions

View File

@ -155,6 +155,7 @@ ErrorPriceExpression19=Expression not found
ErrorPriceExpression20=Empty expression
ErrorPriceExpression21=Empty result '%s'
ErrorPriceExpression22=Negative result '%s'
ErrorPriceExpression23=Unknown or non set variable '%s' in %s
ErrorPriceExpressionInternal=Internal error '%s'
ErrorPriceExpressionUnknown=Unknown error '%s'
ErrorSrcAndTargetWarehouseMustDiffers=Source and target warehouses must differs

View File

@ -85,6 +85,7 @@ class PriceParser
-2 Args
6, wrong number of arguments (%s given, %s expected)
23, unknown or non set variable '%s' after %s
-internal errors
7, internal error
@ -187,13 +188,25 @@ class PriceParser
$this->error_expr = null;
$last_result = null;
//Iterate over each expression splitted by $separator_chr
//Fill each variable in expression from values
$expression = str_replace("\n", $this->separator_chr, $expression);
foreach ($values as $key => $value)
{
if ($value === null) $value = "NULL";
$expression = str_replace($this->special_chr.$key.$this->special_chr, strval($value), $expression);
}
//Check if there is unfilled variable
if (strpos($expression, $this->special_chr) !== false)
{
$data = explode($this->special_chr, $expression);
$variable = $this->special_chr.$data[1];
if (isset($data[2])) $variable.= $this->special_chr;
$this->error_parser = array(23, array($variable, $expression));
return -6;
}
//Iterate over each expression splitted by $separator_chr
$expressions = explode($this->separator_chr, $expression);
$expressions = array_slice($expressions, 0, $this->limit);
foreach ($expressions as $expr) {