mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 10:24:26 +02:00
fix modifier matching regexp
This commit is contained in:
@@ -146,8 +146,8 @@ class Smarty_Compiler extends Smarty {
|
|||||||
// $foo->bar->foo()
|
// $foo->bar->foo()
|
||||||
// $foo->bar->foo->bar()
|
// $foo->bar->foo->bar()
|
||||||
$this->_obj_call_regexp = '(?:' . $this->_obj_start_regexp . '(?:\((?:\w+|'
|
$this->_obj_call_regexp = '(?:' . $this->_obj_start_regexp . '(?:\((?:\w+|'
|
||||||
. $this->_var_regexp . '(?>' . $this->_mod_regexp . ')*(?:\s*,\s*(?:(?:\w+|'
|
. $this->_var_regexp . '(?>' . $this->_mod_regexp . '*)(?:\s*,\s*(?:(?:\w+|'
|
||||||
. $this->_var_regexp . '(?>' . $this->_mod_regexp . ')*)))*)?\))?)';
|
. $this->_var_regexp . '(?>' . $this->_mod_regexp . '*))))*)?\))?)';
|
||||||
|
|
||||||
// matches valid function name:
|
// matches valid function name:
|
||||||
// foo123
|
// foo123
|
||||||
@@ -163,7 +163,7 @@ class Smarty_Compiler extends Smarty {
|
|||||||
// "text"
|
// "text"
|
||||||
// "text"|bar
|
// "text"|bar
|
||||||
// $foo->bar()
|
// $foo->bar()
|
||||||
$this->_param_regexp = '(?:\s*(?:\(array|int\)\s*)?(?:' . $this->_obj_call_regexp . '|' . $this->_var_regexp . '|\w+)(?>' . $this->_mod_regexp . ')*\s*)';
|
$this->_param_regexp = '(?:\s*(?:' . $this->_obj_call_regexp . '|' . $this->_var_regexp . '|\w+)(?>' . $this->_mod_regexp . '*)\s*)';
|
||||||
|
|
||||||
// matches valid parenthesised function parameters:
|
// matches valid parenthesised function parameters:
|
||||||
//
|
//
|
||||||
@@ -355,16 +355,16 @@ class Smarty_Compiler extends Smarty {
|
|||||||
return '';
|
return '';
|
||||||
|
|
||||||
/* Split tag into two three parts: command, command modifiers and the arguments. */
|
/* Split tag into two three parts: command, command modifiers and the arguments. */
|
||||||
if(! preg_match('/^(?:(' . $this->_obj_call_regexp . '|' . $this->_var_regexp . '|\/?' . $this->_func_regexp . ')(' . $this->_mod_regexp . ')*)
|
if(! preg_match('/^(?:(' . $this->_obj_call_regexp . '|' . $this->_var_regexp . '|\/?' . $this->_func_regexp . ')(' . $this->_mod_regexp . '*))
|
||||||
(?:\s+(.*))?$
|
(?:\s+(.*))?$
|
||||||
/xs', $template_tag, $match)) {
|
/xs', $template_tag, $match)) {
|
||||||
$this->_syntax_error("unrecognized tag: $template_tag");
|
$this->_syntax_error("unrecognized tag: $template_tag");
|
||||||
}
|
}
|
||||||
|
|
||||||
$tag_command = $match[1];
|
$tag_command = $match[1];
|
||||||
$tag_modifier = isset($match[2]) ? $match[2] : '';
|
$tag_modifier = isset($match[2]) ? $match[2] : '';
|
||||||
$tag_args = isset($match[3]) ? $match[3] : '';
|
$tag_args = isset($match[3]) ? $match[3] : '';
|
||||||
|
|
||||||
/* If the tag name is not a function, we process it. */
|
/* If the tag name is not a function, we process it. */
|
||||||
|
|
||||||
if (!preg_match('!^\/?' . $this->_func_regexp . '$!', $tag_command)) {
|
if (!preg_match('!^\/?' . $this->_func_regexp . '$!', $tag_command)) {
|
||||||
@@ -966,8 +966,8 @@ class Smarty_Compiler extends Smarty {
|
|||||||
|
|
||||||
/* Tokenize args for 'if' tag. */
|
/* Tokenize args for 'if' tag. */
|
||||||
preg_match_all('/(?>
|
preg_match_all('/(?>
|
||||||
' . $this->_obj_call_regexp . '(?:' . $this->_mod_regexp . ')* | # valid object call
|
' . $this->_obj_call_regexp . '(?:' . $this->_mod_regexp . '*) | # valid object call
|
||||||
' . $this->_var_regexp . '(?:' . $this->_mod_regexp . ')* | # var or quoted string
|
' . $this->_var_regexp . '(?:' . $this->_mod_regexp . '*) | # var or quoted string
|
||||||
\d+|!==|<=>|==|!=|<=|=>|\&\&|\|\||\(|\)|,|\!|\^|=|<|>|\||\% | # valid non-word token
|
\d+|!==|<=>|==|!=|<=|=>|\&\&|\|\||\(|\)|,|\!|\^|=|<|>|\||\% | # valid non-word token
|
||||||
\b\w+\b | # valid word token
|
\b\w+\b | # valid word token
|
||||||
\S+ # anything else
|
\S+ # anything else
|
||||||
@@ -1084,10 +1084,10 @@ class Smarty_Compiler extends Smarty {
|
|||||||
!in_array($token, $this->security_settings['IF_FUNCS'])) {
|
!in_array($token, $this->security_settings['IF_FUNCS'])) {
|
||||||
$this->_syntax_error("(secure mode) '$token' not allowed in if statement");
|
$this->_syntax_error("(secure mode) '$token' not allowed in if statement");
|
||||||
}
|
}
|
||||||
} elseif(preg_match('!^' . $this->_var_regexp . '(?:' . $this->_mod_regexp . ')*$!', $token)) {
|
} elseif(preg_match('!^' . $this->_var_regexp . '(?:' . $this->_mod_regexp . '*)$!', $token)) {
|
||||||
// variable
|
// variable
|
||||||
$token = $this->_parse_var_props($token);
|
$token = $this->_parse_var_props($token);
|
||||||
} elseif(preg_match('!^' . $this->_obj_call_regexp . '(?:' . $this->_mod_regexp . ')*$!', $token)) {
|
} elseif(preg_match('!^' . $this->_obj_call_regexp . '(?:' . $this->_mod_regexp . '*)$!', $token)) {
|
||||||
// object
|
// object
|
||||||
$token = $this->_parse_var_props($token);
|
$token = $this->_parse_var_props($token);
|
||||||
} elseif(is_numeric($token)) {
|
} elseif(is_numeric($token)) {
|
||||||
@@ -1257,32 +1257,32 @@ class Smarty_Compiler extends Smarty {
|
|||||||
|
|
||||||
$val = trim($val);
|
$val = trim($val);
|
||||||
|
|
||||||
if(preg_match('!^(' . $this->_obj_call_regexp . '|' . $this->_dvar_regexp . ')(?:' . $this->_mod_regexp . ')*$!', $val)) {
|
if(preg_match('!^(' . $this->_obj_call_regexp . '|' . $this->_dvar_regexp . ')(?:' . $this->_mod_regexp . '*)$!', $val)) {
|
||||||
// $ variable or object
|
// $ variable or object
|
||||||
return $this->_parse_var($val);
|
return $this->_parse_var($val);
|
||||||
}
|
}
|
||||||
elseif(preg_match('!^' . $this->_db_qstr_regexp . '(?:' . $this->_mod_regexp . ')*$!', $val)) {
|
elseif(preg_match('!^' . $this->_db_qstr_regexp . '(?:' . $this->_mod_regexp . '*)$!', $val)) {
|
||||||
// double quoted text
|
// double quoted text
|
||||||
preg_match('!^(' . $this->_db_qstr_regexp . ')('. $this->_mod_regexp . ')*$!', $val, $match);
|
preg_match('!^(' . $this->_db_qstr_regexp . ')('. $this->_mod_regexp . '*)$!', $val, $match);
|
||||||
$return = $this->_expand_quoted_text($match[1]);
|
$return = $this->_expand_quoted_text($match[1]);
|
||||||
if($match[2] != '') {
|
if($match[2] != '') {
|
||||||
$this->_parse_modifiers($return, $match[2]);
|
$this->_parse_modifiers($return, $match[2]);
|
||||||
}
|
}
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
elseif(preg_match('!^' . $this->_si_qstr_regexp . '(?:' . $this->_mod_regexp . ')*$!', $val)) {
|
elseif(preg_match('!^' . $this->_si_qstr_regexp . '(?:' . $this->_mod_regexp . '*)$!', $val)) {
|
||||||
// single quoted text
|
// single quoted text
|
||||||
preg_match('!^(' . $this->_si_qstr_regexp . ')('. $this->_mod_regexp . ')*$!', $val, $match);
|
preg_match('!^(' . $this->_si_qstr_regexp . ')('. $this->_mod_regexp . '*)$!', $val, $match);
|
||||||
if($match[2] != '') {
|
if($match[2] != '') {
|
||||||
$this->_parse_modifiers($match[1], $match[2]);
|
$this->_parse_modifiers($match[1], $match[2]);
|
||||||
return $match[1];
|
return $match[1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
elseif(preg_match('!^' . $this->_cvar_regexp . '(?:' . $this->_mod_regexp . ')*$!', $val)) {
|
elseif(preg_match('!^' . $this->_cvar_regexp . '(?:' . $this->_mod_regexp . '*)$!', $val)) {
|
||||||
// config var
|
// config var
|
||||||
return $this->_parse_conf_var($val);
|
return $this->_parse_conf_var($val);
|
||||||
}
|
}
|
||||||
elseif(preg_match('!^' . $this->_svar_regexp . '(?:' . $this->_mod_regexp . ')*$!', $val)) {
|
elseif(preg_match('!^' . $this->_svar_regexp . '(?:' . $this->_mod_regexp . '*)$!', $val)) {
|
||||||
// section var
|
// section var
|
||||||
return $this->_parse_section_prop($val);
|
return $this->_parse_section_prop($val);
|
||||||
}
|
}
|
||||||
@@ -1319,7 +1319,7 @@ class Smarty_Compiler extends Smarty {
|
|||||||
function _parse_var($var_expr)
|
function _parse_var($var_expr)
|
||||||
{
|
{
|
||||||
|
|
||||||
preg_match('!(' . $this->_obj_call_regexp . '|' . $this->_var_regexp . ')(' . $this->_mod_regexp . ')*$!', $var_expr, $match);
|
preg_match('!(' . $this->_obj_call_regexp . '|' . $this->_var_regexp . ')(' . $this->_mod_regexp . '*)$!', $var_expr, $match);
|
||||||
|
|
||||||
$var_ref = substr($match[1],1);
|
$var_ref = substr($match[1],1);
|
||||||
$modifiers = $match[2];
|
$modifiers = $match[2];
|
||||||
|
@@ -146,8 +146,8 @@ class Smarty_Compiler extends Smarty {
|
|||||||
// $foo->bar->foo()
|
// $foo->bar->foo()
|
||||||
// $foo->bar->foo->bar()
|
// $foo->bar->foo->bar()
|
||||||
$this->_obj_call_regexp = '(?:' . $this->_obj_start_regexp . '(?:\((?:\w+|'
|
$this->_obj_call_regexp = '(?:' . $this->_obj_start_regexp . '(?:\((?:\w+|'
|
||||||
. $this->_var_regexp . '(?>' . $this->_mod_regexp . ')*(?:\s*,\s*(?:(?:\w+|'
|
. $this->_var_regexp . '(?>' . $this->_mod_regexp . '*)(?:\s*,\s*(?:(?:\w+|'
|
||||||
. $this->_var_regexp . '(?>' . $this->_mod_regexp . ')*)))*)?\))?)';
|
. $this->_var_regexp . '(?>' . $this->_mod_regexp . '*))))*)?\))?)';
|
||||||
|
|
||||||
// matches valid function name:
|
// matches valid function name:
|
||||||
// foo123
|
// foo123
|
||||||
@@ -163,7 +163,7 @@ class Smarty_Compiler extends Smarty {
|
|||||||
// "text"
|
// "text"
|
||||||
// "text"|bar
|
// "text"|bar
|
||||||
// $foo->bar()
|
// $foo->bar()
|
||||||
$this->_param_regexp = '(?:\s*(?:\(array|int\)\s*)?(?:' . $this->_obj_call_regexp . '|' . $this->_var_regexp . '|\w+)(?>' . $this->_mod_regexp . ')*\s*)';
|
$this->_param_regexp = '(?:\s*(?:' . $this->_obj_call_regexp . '|' . $this->_var_regexp . '|\w+)(?>' . $this->_mod_regexp . '*)\s*)';
|
||||||
|
|
||||||
// matches valid parenthesised function parameters:
|
// matches valid parenthesised function parameters:
|
||||||
//
|
//
|
||||||
@@ -355,16 +355,16 @@ class Smarty_Compiler extends Smarty {
|
|||||||
return '';
|
return '';
|
||||||
|
|
||||||
/* Split tag into two three parts: command, command modifiers and the arguments. */
|
/* Split tag into two three parts: command, command modifiers and the arguments. */
|
||||||
if(! preg_match('/^(?:(' . $this->_obj_call_regexp . '|' . $this->_var_regexp . '|\/?' . $this->_func_regexp . ')(' . $this->_mod_regexp . ')*)
|
if(! preg_match('/^(?:(' . $this->_obj_call_regexp . '|' . $this->_var_regexp . '|\/?' . $this->_func_regexp . ')(' . $this->_mod_regexp . '*))
|
||||||
(?:\s+(.*))?$
|
(?:\s+(.*))?$
|
||||||
/xs', $template_tag, $match)) {
|
/xs', $template_tag, $match)) {
|
||||||
$this->_syntax_error("unrecognized tag: $template_tag");
|
$this->_syntax_error("unrecognized tag: $template_tag");
|
||||||
}
|
}
|
||||||
|
|
||||||
$tag_command = $match[1];
|
$tag_command = $match[1];
|
||||||
$tag_modifier = isset($match[2]) ? $match[2] : '';
|
$tag_modifier = isset($match[2]) ? $match[2] : '';
|
||||||
$tag_args = isset($match[3]) ? $match[3] : '';
|
$tag_args = isset($match[3]) ? $match[3] : '';
|
||||||
|
|
||||||
/* If the tag name is not a function, we process it. */
|
/* If the tag name is not a function, we process it. */
|
||||||
|
|
||||||
if (!preg_match('!^\/?' . $this->_func_regexp . '$!', $tag_command)) {
|
if (!preg_match('!^\/?' . $this->_func_regexp . '$!', $tag_command)) {
|
||||||
@@ -966,8 +966,8 @@ class Smarty_Compiler extends Smarty {
|
|||||||
|
|
||||||
/* Tokenize args for 'if' tag. */
|
/* Tokenize args for 'if' tag. */
|
||||||
preg_match_all('/(?>
|
preg_match_all('/(?>
|
||||||
' . $this->_obj_call_regexp . '(?:' . $this->_mod_regexp . ')* | # valid object call
|
' . $this->_obj_call_regexp . '(?:' . $this->_mod_regexp . '*) | # valid object call
|
||||||
' . $this->_var_regexp . '(?:' . $this->_mod_regexp . ')* | # var or quoted string
|
' . $this->_var_regexp . '(?:' . $this->_mod_regexp . '*) | # var or quoted string
|
||||||
\d+|!==|<=>|==|!=|<=|=>|\&\&|\|\||\(|\)|,|\!|\^|=|<|>|\||\% | # valid non-word token
|
\d+|!==|<=>|==|!=|<=|=>|\&\&|\|\||\(|\)|,|\!|\^|=|<|>|\||\% | # valid non-word token
|
||||||
\b\w+\b | # valid word token
|
\b\w+\b | # valid word token
|
||||||
\S+ # anything else
|
\S+ # anything else
|
||||||
@@ -1084,10 +1084,10 @@ class Smarty_Compiler extends Smarty {
|
|||||||
!in_array($token, $this->security_settings['IF_FUNCS'])) {
|
!in_array($token, $this->security_settings['IF_FUNCS'])) {
|
||||||
$this->_syntax_error("(secure mode) '$token' not allowed in if statement");
|
$this->_syntax_error("(secure mode) '$token' not allowed in if statement");
|
||||||
}
|
}
|
||||||
} elseif(preg_match('!^' . $this->_var_regexp . '(?:' . $this->_mod_regexp . ')*$!', $token)) {
|
} elseif(preg_match('!^' . $this->_var_regexp . '(?:' . $this->_mod_regexp . '*)$!', $token)) {
|
||||||
// variable
|
// variable
|
||||||
$token = $this->_parse_var_props($token);
|
$token = $this->_parse_var_props($token);
|
||||||
} elseif(preg_match('!^' . $this->_obj_call_regexp . '(?:' . $this->_mod_regexp . ')*$!', $token)) {
|
} elseif(preg_match('!^' . $this->_obj_call_regexp . '(?:' . $this->_mod_regexp . '*)$!', $token)) {
|
||||||
// object
|
// object
|
||||||
$token = $this->_parse_var_props($token);
|
$token = $this->_parse_var_props($token);
|
||||||
} elseif(is_numeric($token)) {
|
} elseif(is_numeric($token)) {
|
||||||
@@ -1257,32 +1257,32 @@ class Smarty_Compiler extends Smarty {
|
|||||||
|
|
||||||
$val = trim($val);
|
$val = trim($val);
|
||||||
|
|
||||||
if(preg_match('!^(' . $this->_obj_call_regexp . '|' . $this->_dvar_regexp . ')(?:' . $this->_mod_regexp . ')*$!', $val)) {
|
if(preg_match('!^(' . $this->_obj_call_regexp . '|' . $this->_dvar_regexp . ')(?:' . $this->_mod_regexp . '*)$!', $val)) {
|
||||||
// $ variable or object
|
// $ variable or object
|
||||||
return $this->_parse_var($val);
|
return $this->_parse_var($val);
|
||||||
}
|
}
|
||||||
elseif(preg_match('!^' . $this->_db_qstr_regexp . '(?:' . $this->_mod_regexp . ')*$!', $val)) {
|
elseif(preg_match('!^' . $this->_db_qstr_regexp . '(?:' . $this->_mod_regexp . '*)$!', $val)) {
|
||||||
// double quoted text
|
// double quoted text
|
||||||
preg_match('!^(' . $this->_db_qstr_regexp . ')('. $this->_mod_regexp . ')*$!', $val, $match);
|
preg_match('!^(' . $this->_db_qstr_regexp . ')('. $this->_mod_regexp . '*)$!', $val, $match);
|
||||||
$return = $this->_expand_quoted_text($match[1]);
|
$return = $this->_expand_quoted_text($match[1]);
|
||||||
if($match[2] != '') {
|
if($match[2] != '') {
|
||||||
$this->_parse_modifiers($return, $match[2]);
|
$this->_parse_modifiers($return, $match[2]);
|
||||||
}
|
}
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
elseif(preg_match('!^' . $this->_si_qstr_regexp . '(?:' . $this->_mod_regexp . ')*$!', $val)) {
|
elseif(preg_match('!^' . $this->_si_qstr_regexp . '(?:' . $this->_mod_regexp . '*)$!', $val)) {
|
||||||
// single quoted text
|
// single quoted text
|
||||||
preg_match('!^(' . $this->_si_qstr_regexp . ')('. $this->_mod_regexp . ')*$!', $val, $match);
|
preg_match('!^(' . $this->_si_qstr_regexp . ')('. $this->_mod_regexp . '*)$!', $val, $match);
|
||||||
if($match[2] != '') {
|
if($match[2] != '') {
|
||||||
$this->_parse_modifiers($match[1], $match[2]);
|
$this->_parse_modifiers($match[1], $match[2]);
|
||||||
return $match[1];
|
return $match[1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
elseif(preg_match('!^' . $this->_cvar_regexp . '(?:' . $this->_mod_regexp . ')*$!', $val)) {
|
elseif(preg_match('!^' . $this->_cvar_regexp . '(?:' . $this->_mod_regexp . '*)$!', $val)) {
|
||||||
// config var
|
// config var
|
||||||
return $this->_parse_conf_var($val);
|
return $this->_parse_conf_var($val);
|
||||||
}
|
}
|
||||||
elseif(preg_match('!^' . $this->_svar_regexp . '(?:' . $this->_mod_regexp . ')*$!', $val)) {
|
elseif(preg_match('!^' . $this->_svar_regexp . '(?:' . $this->_mod_regexp . '*)$!', $val)) {
|
||||||
// section var
|
// section var
|
||||||
return $this->_parse_section_prop($val);
|
return $this->_parse_section_prop($val);
|
||||||
}
|
}
|
||||||
@@ -1319,7 +1319,7 @@ class Smarty_Compiler extends Smarty {
|
|||||||
function _parse_var($var_expr)
|
function _parse_var($var_expr)
|
||||||
{
|
{
|
||||||
|
|
||||||
preg_match('!(' . $this->_obj_call_regexp . '|' . $this->_var_regexp . ')(' . $this->_mod_regexp . ')*$!', $var_expr, $match);
|
preg_match('!(' . $this->_obj_call_regexp . '|' . $this->_var_regexp . ')(' . $this->_mod_regexp . '*)$!', $var_expr, $match);
|
||||||
|
|
||||||
$var_ref = substr($match[1],1);
|
$var_ref = substr($match[1],1);
|
||||||
$modifiers = $match[2];
|
$modifiers = $match[2];
|
||||||
|
Reference in New Issue
Block a user