mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 10:24:26 +02:00
check strict syntax of function attributes
This commit is contained in:
4
NEWS
4
NEWS
@@ -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)
|
||||||
----------------------------
|
----------------------------
|
||||||
|
@@ -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);
|
||||||
@@ -1321,7 +1320,7 @@ class Smarty_Compiler extends Smarty {
|
|||||||
[=]
|
[=]
|
||||||
/x', $tag_args, $match);
|
/x', $tag_args, $match);
|
||||||
$tokens = $match[0];
|
$tokens = $match[0];
|
||||||
|
|
||||||
$attrs = array();
|
$attrs = array();
|
||||||
/* Parse state:
|
/* Parse state:
|
||||||
0 - expecting attribute name
|
0 - expecting attribute name
|
||||||
@@ -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;
|
||||||
/* If the token is just a string,
|
} else if (preg_match('!^[\w\.]+$!', $token)) {
|
||||||
we double-quote it. */
|
/* If the token is just a string,
|
||||||
else if (preg_match('!^\w+$!', $token)) {
|
we double-quote it. */
|
||||||
$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;
|
||||||
|
@@ -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);
|
||||||
@@ -1321,7 +1320,7 @@ class Smarty_Compiler extends Smarty {
|
|||||||
[=]
|
[=]
|
||||||
/x', $tag_args, $match);
|
/x', $tag_args, $match);
|
||||||
$tokens = $match[0];
|
$tokens = $match[0];
|
||||||
|
|
||||||
$attrs = array();
|
$attrs = array();
|
||||||
/* Parse state:
|
/* Parse state:
|
||||||
0 - expecting attribute name
|
0 - expecting attribute name
|
||||||
@@ -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;
|
||||||
/* If the token is just a string,
|
} else if (preg_match('!^[\w\.]+$!', $token)) {
|
||||||
we double-quote it. */
|
/* If the token is just a string,
|
||||||
else if (preg_match('!^\w+$!', $token)) {
|
we double-quote it. */
|
||||||
$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;
|
||||||
|
Reference in New Issue
Block a user