mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-02 09:24:28 +02:00
Switched to a more advanced regex to test wheter parameter is a variable
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
- fix foreachelse on arrayiterators https://github.com/smarty-php/smarty/issues/506
|
- fix foreachelse on arrayiterators https://github.com/smarty-php/smarty/issues/506
|
||||||
|
- fix errors that occured where isset was replaced with null check such as https://github.com/smarty-php/smarty/issues/453
|
||||||
|
|
||||||
===== 3.1.34 release ===== 05.11.2019
|
===== 3.1.34 release ===== 05.11.2019
|
||||||
13.01.2020
|
13.01.2020
|
||||||
|
@@ -621,14 +621,18 @@ abstract class Smarty_Internal_TemplateCompilerBase
|
|||||||
|| strcasecmp($name, 'array') === 0 || is_callable($name)
|
|| strcasecmp($name, 'array') === 0 || is_callable($name)
|
||||||
) {
|
) {
|
||||||
$func_name = strtolower($name);
|
$func_name = strtolower($name);
|
||||||
$par = implode(',', $parameter);
|
|
||||||
$parHasFuction = strpos($par, '(') !== false;
|
|
||||||
if ($func_name === 'isset') {
|
if ($func_name === 'isset') {
|
||||||
if (count($parameter) === 0) {
|
if (count($parameter) === 0) {
|
||||||
$this->trigger_template_error('Illegal number of parameter in "isset()"');
|
$this->trigger_template_error('Illegal number of parameter in "isset()"');
|
||||||
}
|
}
|
||||||
$isset_par = str_replace("')->value", "',null,true,false)->value", $par);
|
|
||||||
return '@!is_null(' . $isset_par . ')';
|
$pa = array();
|
||||||
|
foreach ($parameter as $p) {
|
||||||
|
$pa[] = $this->syntaxMatchesVariable($p) ? 'isset(' . $p . ')' : '(' . $p . ' !== null )';
|
||||||
|
}
|
||||||
|
return '(' . implode(' && ', $pa) . ')';
|
||||||
|
|
||||||
} elseif (in_array(
|
} elseif (in_array(
|
||||||
$func_name,
|
$func_name,
|
||||||
array(
|
array(
|
||||||
@@ -645,7 +649,7 @@ abstract class Smarty_Internal_TemplateCompilerBase
|
|||||||
$this->trigger_template_error("Illegal number of parameter in '{$func_name()}'");
|
$this->trigger_template_error("Illegal number of parameter in '{$func_name()}'");
|
||||||
}
|
}
|
||||||
if ($func_name === 'empty') {
|
if ($func_name === 'empty') {
|
||||||
if ($parHasFuction && version_compare(PHP_VERSION, '5.5.0', '<')) {
|
if (!$this->syntaxMatchesVariable($parameter[0]) && version_compare(PHP_VERSION, '5.5.0', '<')) {
|
||||||
return '(' . $parameter[ 0 ] . ' === false )';
|
return '(' . $parameter[ 0 ] . ' === false )';
|
||||||
} else {
|
} else {
|
||||||
return $func_name . '(' .
|
return $func_name . '(' .
|
||||||
@@ -663,6 +667,18 @@ abstract class Smarty_Internal_TemplateCompilerBase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines whether the passed string represents a valid (PHP) variable.
|
||||||
|
* This is important, because `isset()` only works on variables and `empty()` can only be passed
|
||||||
|
* a variable prior to php5.5
|
||||||
|
* @param $string
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
private function syntaxMatchesVariable($string) {
|
||||||
|
static $regex_pattern = '/^\$[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*((->)[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*|\[.*]*\])*$/';
|
||||||
|
return 1 === preg_match($regex_pattern, trim($string));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method is called from parser to process a text content section
|
* This method is called from parser to process a text content section
|
||||||
* - remove text from inheritance child templates as they may generate output
|
* - remove text from inheritance child templates as they may generate output
|
||||||
|
Reference in New Issue
Block a user