check strict syntax of function attributes

This commit is contained in:
mohrt
2003-02-13 15:28:14 +00:00
parent 7aba4537a9
commit 6cb413bbfc
3 changed files with 25 additions and 21 deletions

4
NEWS
View File

@@ -1,5 +1,7 @@
- check strict syntax of function attributes (Monte)
- dropped support for modifers on object parameters, - dropped support for modifers on object parameters,
added support for objects as modifier parameters added support for objects as modifier parameters (Monte)
- fixed bug with decimal numbers in if statements (Monte)
Version 2.4.2 (Feb 11, 2003) Version 2.4.2 (Feb 11, 2003)
---------------------------- ----------------------------

View File

@@ -162,7 +162,7 @@ class Smarty_Compiler extends Smarty {
$this->_func_regexp = '[a-zA-Z_]\w*'; $this->_func_regexp = '[a-zA-Z_]\w*';
// matches valid registered object: // matches valid registered object:
// foo.bar // foo->bar
$this->_reg_obj_regexp = '[a-zA-Z_]\w*->[a-zA-Z_]\w*'; $this->_reg_obj_regexp = '[a-zA-Z_]\w*->[a-zA-Z_]\w*';
// matches valid parameter values: // matches valid parameter values:
@@ -193,7 +193,6 @@ class Smarty_Compiler extends Smarty {
// foo123($foo,$foo->bar(),"foo") // foo123($foo,$foo->bar(),"foo")
$this->_func_call_regexp = '(?:' . $this->_func_regexp . '\s*(?:' $this->_func_call_regexp = '(?:' . $this->_func_regexp . '\s*(?:'
. $this->_parenth_param_regexp . '))'; . $this->_parenth_param_regexp . '))';
} }
/** /**
@@ -1097,7 +1096,7 @@ class Smarty_Compiler extends Smarty {
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+(?:\.\d+)?|!==|<=>|==|!=|<=|>=|\&\&|\|\||\(|\)|,|\!|\^|=|<|>|\||\%|\+|\-|\/|\* | # valid non-word token \-?\d+(?:\.\d+)?|\.\d+|!==|<=>|==|!=|<=|>=|\&\&|\|\||\(|\)|,|\!|\^|=|\&|\~|<|>|\||\%|\+|\-|\/|\* | # valid non-word token
\b\w+\b | # valid word token \b\w+\b | # valid word token
\S+ # anything else \S+ # anything else
)/x', $tag_args, $match); )/x', $tag_args, $match);
@@ -1338,7 +1337,7 @@ class Smarty_Compiler extends Smarty {
$attr_name = $token; $attr_name = $token;
$state = 1; $state = 1;
} else } else
$this->_syntax_error("invalid attribute name - '$token'", E_USER_ERROR, __FILE__, __LINE__); $this->_syntax_error("invalid attribute name: '$token'", E_USER_ERROR, __FILE__, __LINE__);
break; break;
case 1: case 1:
@@ -1355,14 +1354,16 @@ class Smarty_Compiler extends Smarty {
if ($token != '=') { if ($token != '=') {
/* We booleanize the token if it's a non-quoted possible /* We booleanize the token if it's a non-quoted possible
boolean value. */ boolean value. */
if (preg_match('!^(on|yes|true)$!', $token)) if (preg_match('!^(on|yes|true)$!', $token)) {
$token = true; $token = true;
else if (preg_match('!^(off|no|false)$!', $token)) } else if (preg_match('!^(off|no|false)$!', $token)) {
$token = false; $token = false;
} else if (preg_match('!^[\w\.]+$!', $token)) {
/* If the token is just a string, /* If the token is just a string,
we double-quote it. */ we double-quote it. */
else if (preg_match('!^\w+$!', $token)) {
$token = '"'.$token.'"'; $token = '"'.$token.'"';
} else if (!preg_match('!^' . $this->_obj_call_regexp . '|' . $this->_var_regexp . '(?:' . $this->_mod_regexp . ')?$!', $token)) {
$this->_syntax_error("invalid attribute value: '$token'", E_USER_ERROR, __FILE__, __LINE__);
} }
$attrs[$attr_name] = $token; $attrs[$attr_name] = $token;

View File

@@ -162,7 +162,7 @@ class Smarty_Compiler extends Smarty {
$this->_func_regexp = '[a-zA-Z_]\w*'; $this->_func_regexp = '[a-zA-Z_]\w*';
// matches valid registered object: // matches valid registered object:
// foo.bar // foo->bar
$this->_reg_obj_regexp = '[a-zA-Z_]\w*->[a-zA-Z_]\w*'; $this->_reg_obj_regexp = '[a-zA-Z_]\w*->[a-zA-Z_]\w*';
// matches valid parameter values: // matches valid parameter values:
@@ -193,7 +193,6 @@ class Smarty_Compiler extends Smarty {
// foo123($foo,$foo->bar(),"foo") // foo123($foo,$foo->bar(),"foo")
$this->_func_call_regexp = '(?:' . $this->_func_regexp . '\s*(?:' $this->_func_call_regexp = '(?:' . $this->_func_regexp . '\s*(?:'
. $this->_parenth_param_regexp . '))'; . $this->_parenth_param_regexp . '))';
} }
/** /**
@@ -1097,7 +1096,7 @@ class Smarty_Compiler extends Smarty {
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+(?:\.\d+)?|!==|<=>|==|!=|<=|>=|\&\&|\|\||\(|\)|,|\!|\^|=|<|>|\||\%|\+|\-|\/|\* | # valid non-word token \-?\d+(?:\.\d+)?|\.\d+|!==|<=>|==|!=|<=|>=|\&\&|\|\||\(|\)|,|\!|\^|=|\&|\~|<|>|\||\%|\+|\-|\/|\* | # valid non-word token
\b\w+\b | # valid word token \b\w+\b | # valid word token
\S+ # anything else \S+ # anything else
)/x', $tag_args, $match); )/x', $tag_args, $match);
@@ -1338,7 +1337,7 @@ class Smarty_Compiler extends Smarty {
$attr_name = $token; $attr_name = $token;
$state = 1; $state = 1;
} else } else
$this->_syntax_error("invalid attribute name - '$token'", E_USER_ERROR, __FILE__, __LINE__); $this->_syntax_error("invalid attribute name: '$token'", E_USER_ERROR, __FILE__, __LINE__);
break; break;
case 1: case 1:
@@ -1355,14 +1354,16 @@ class Smarty_Compiler extends Smarty {
if ($token != '=') { if ($token != '=') {
/* We booleanize the token if it's a non-quoted possible /* We booleanize the token if it's a non-quoted possible
boolean value. */ boolean value. */
if (preg_match('!^(on|yes|true)$!', $token)) if (preg_match('!^(on|yes|true)$!', $token)) {
$token = true; $token = true;
else if (preg_match('!^(off|no|false)$!', $token)) } else if (preg_match('!^(off|no|false)$!', $token)) {
$token = false; $token = false;
} else if (preg_match('!^[\w\.]+$!', $token)) {
/* If the token is just a string, /* If the token is just a string,
we double-quote it. */ we double-quote it. */
else if (preg_match('!^\w+$!', $token)) {
$token = '"'.$token.'"'; $token = '"'.$token.'"';
} else if (!preg_match('!^' . $this->_obj_call_regexp . '|' . $this->_var_regexp . '(?:' . $this->_mod_regexp . ')?$!', $token)) {
$this->_syntax_error("invalid attribute value: '$token'", E_USER_ERROR, __FILE__, __LINE__);
} }
$attrs[$attr_name] = $token; $attrs[$attr_name] = $token;