fix modifier matching regexp

This commit is contained in:
mohrt
2002-12-24 14:56:43 +00:00
parent 7a604a79ab
commit 70f61e47da
2 changed files with 38 additions and 38 deletions

View File

@@ -146,8 +146,8 @@ class Smarty_Compiler extends Smarty {
// $foo->bar->foo()
// $foo->bar->foo->bar()
$this->_obj_call_regexp = '(?:' . $this->_obj_start_regexp . '(?:\((?:\w+|'
. $this->_var_regexp . '(?>' . $this->_mod_regexp . ')*(?:\s*,\s*(?:(?:\w+|'
. $this->_var_regexp . '(?>' . $this->_mod_regexp . ')*)))*)?\))?)';
. $this->_var_regexp . '(?>' . $this->_mod_regexp . '*)(?:\s*,\s*(?:(?:\w+|'
. $this->_var_regexp . '(?>' . $this->_mod_regexp . '*))))*)?\))?)';
// matches valid function name:
// foo123
@@ -163,7 +163,7 @@ class Smarty_Compiler extends Smarty {
// "text"
// "text"|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:
//
@@ -355,16 +355,16 @@ class Smarty_Compiler extends Smarty {
return '';
/* 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+(.*))?$
/xs', $template_tag, $match)) {
$this->_syntax_error("unrecognized tag: $template_tag");
}
$tag_command = $match[1];
$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 (!preg_match('!^\/?' . $this->_func_regexp . '$!', $tag_command)) {
@@ -966,8 +966,8 @@ class Smarty_Compiler extends Smarty {
/* Tokenize args for 'if' tag. */
preg_match_all('/(?>
' . $this->_obj_call_regexp . '(?:' . $this->_mod_regexp . ')* | # valid object call
' . $this->_var_regexp . '(?:' . $this->_mod_regexp . ')* | # var or quoted string
' . $this->_obj_call_regexp . '(?:' . $this->_mod_regexp . '*) | # valid object call
' . $this->_var_regexp . '(?:' . $this->_mod_regexp . '*) | # var or quoted string
\d+|!==|<=>|==|!=|<=|=>|\&\&|\|\||\(|\)|,|\!|\^|=|<|>|\||\% | # valid non-word token
\b\w+\b | # valid word token
\S+ # anything else
@@ -1084,10 +1084,10 @@ class Smarty_Compiler extends Smarty {
!in_array($token, $this->security_settings['IF_FUNCS'])) {
$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
$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
$token = $this->_parse_var_props($token);
} elseif(is_numeric($token)) {
@@ -1257,32 +1257,32 @@ class Smarty_Compiler extends Smarty {
$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
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
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]);
if($match[2] != '') {
$this->_parse_modifiers($return, $match[2]);
}
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
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] != '') {
$this->_parse_modifiers($match[1], $match[2]);
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
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
return $this->_parse_section_prop($val);
}
@@ -1319,7 +1319,7 @@ class Smarty_Compiler extends Smarty {
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);
$modifiers = $match[2];

View File

@@ -146,8 +146,8 @@ class Smarty_Compiler extends Smarty {
// $foo->bar->foo()
// $foo->bar->foo->bar()
$this->_obj_call_regexp = '(?:' . $this->_obj_start_regexp . '(?:\((?:\w+|'
. $this->_var_regexp . '(?>' . $this->_mod_regexp . ')*(?:\s*,\s*(?:(?:\w+|'
. $this->_var_regexp . '(?>' . $this->_mod_regexp . ')*)))*)?\))?)';
. $this->_var_regexp . '(?>' . $this->_mod_regexp . '*)(?:\s*,\s*(?:(?:\w+|'
. $this->_var_regexp . '(?>' . $this->_mod_regexp . '*))))*)?\))?)';
// matches valid function name:
// foo123
@@ -163,7 +163,7 @@ class Smarty_Compiler extends Smarty {
// "text"
// "text"|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:
//
@@ -355,16 +355,16 @@ class Smarty_Compiler extends Smarty {
return '';
/* 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+(.*))?$
/xs', $template_tag, $match)) {
$this->_syntax_error("unrecognized tag: $template_tag");
}
$tag_command = $match[1];
$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 (!preg_match('!^\/?' . $this->_func_regexp . '$!', $tag_command)) {
@@ -966,8 +966,8 @@ class Smarty_Compiler extends Smarty {
/* Tokenize args for 'if' tag. */
preg_match_all('/(?>
' . $this->_obj_call_regexp . '(?:' . $this->_mod_regexp . ')* | # valid object call
' . $this->_var_regexp . '(?:' . $this->_mod_regexp . ')* | # var or quoted string
' . $this->_obj_call_regexp . '(?:' . $this->_mod_regexp . '*) | # valid object call
' . $this->_var_regexp . '(?:' . $this->_mod_regexp . '*) | # var or quoted string
\d+|!==|<=>|==|!=|<=|=>|\&\&|\|\||\(|\)|,|\!|\^|=|<|>|\||\% | # valid non-word token
\b\w+\b | # valid word token
\S+ # anything else
@@ -1084,10 +1084,10 @@ class Smarty_Compiler extends Smarty {
!in_array($token, $this->security_settings['IF_FUNCS'])) {
$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
$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
$token = $this->_parse_var_props($token);
} elseif(is_numeric($token)) {
@@ -1257,32 +1257,32 @@ class Smarty_Compiler extends Smarty {
$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
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
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]);
if($match[2] != '') {
$this->_parse_modifiers($return, $match[2]);
}
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
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] != '') {
$this->_parse_modifiers($match[1], $match[2]);
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
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
return $this->_parse_section_prop($val);
}
@@ -1319,7 +1319,7 @@ class Smarty_Compiler extends Smarty {
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);
$modifiers = $match[2];