From b04bbd47c6e05df11f9593720508226d61b7444b Mon Sep 17 00:00:00 2001 From: mohrt Date: Mon, 17 Feb 2003 14:47:21 +0000 Subject: [PATCH] add @ and === to if tokens, few param cleanups --- NEWS | 5 +++++ Smarty.class.php | 1 + Smarty_Compiler.class.php | 10 ++++++---- libs/Smarty.class.php | 1 + libs/Smarty_Compiler.class.php | 10 ++++++---- 5 files changed, 19 insertions(+), 8 deletions(-) diff --git a/NEWS b/NEWS index 7cd168bb..4f458795 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,8 @@ + - clean up param calls to _parse_var and _parse_attrs (Monte) + - define $template_source var, elude possible warning + (Monte) + - fix syntax problem with evaluating PHP constants (Monte) + - add @ and === as valid if statement tokens (Monte) - enable error messages for config_load errors, use $this->config_class for loading class name (Monte) - fix html_options to not escape already escaped entities (Monte) diff --git a/Smarty.class.php b/Smarty.class.php index 2dc16162..e3a465be 100644 --- a/Smarty.class.php +++ b/Smarty.class.php @@ -1418,6 +1418,7 @@ class Smarty } } else if ($resource_type != 'file') { $readable = true; + $template_source = null; $resource_func = $this->_plugins['resource'][$resource_type][0][0]; $readable = $resource_func($resource_name, $template_source, $this); } diff --git a/Smarty_Compiler.class.php b/Smarty_Compiler.class.php index 975d3402..8bfc98b5 100644 --- a/Smarty_Compiler.class.php +++ b/Smarty_Compiler.class.php @@ -1086,7 +1086,7 @@ class Smarty_Compiler extends Smarty { preg_match_all('/(?> ' . $this->_obj_call_regexp . '(?:' . $this->_mod_regexp . '*) | # valid object call ' . $this->_var_regexp . '(?:' . $this->_mod_regexp . '*) | # var or quoted string - \-?\d+(?:\.\d+)?|\.\d+|!==|<=>|==|!=|<=|>=|\&\&|\|\||\(|\)|,|\!|\^|=|\&|\~|<|>|\||\%|\+|\-|\/|\* | # valid non-word token + \-?\d+(?:\.\d+)?|\.\d+|!==|<=>|===|==|!=|<=|>=|\&\&|\|\||\(|\)|,|\!|\^|=|\&|\~|<|>|\||\%|\+|\-|\/|\*|\@ | # valid non-word token \b\w+\b | # valid word token \S+ # anything else )/x', $tag_args, $match); @@ -1110,6 +1110,7 @@ class Smarty_Compiler extends Smarty { case '%': case '!==': case '==': + case '===': case '>': case '<': case '!=': @@ -1127,6 +1128,7 @@ class Smarty_Compiler extends Smarty { case '-': case '*': case '/': + case '@': break; case 'eq': @@ -1346,7 +1348,7 @@ class Smarty_Compiler extends Smarty { $token = true; } else if (preg_match('!^(off|no|false)$!', $token)) { $token = false; - } else if (preg_match('!^[\w\.-]+$!', $token)) { + } else if ($quote && preg_match('!^[\w\.-]+$!', $token)) { /* If the token is just a string, we double-quote it. */ $token = '"'.$token.'"'; @@ -1403,7 +1405,7 @@ class Smarty_Compiler extends Smarty { if(preg_match('!^(' . $this->_obj_call_regexp . '|' . $this->_dvar_regexp . ')(?:' . $this->_mod_regexp . '*)$!', $val)) { // $ variable or object - return $this->_parse_var($val, $tag_attrs); + return $this->_parse_var($val); } elseif(preg_match('!^' . $this->_db_qstr_regexp . '(?:' . $this->_mod_regexp . '*)$!', $val)) { // double quoted text @@ -1778,7 +1780,7 @@ class Smarty_Compiler extends Smarty { case 'const': array_shift($indexes); - $compiled_ref = 'defined(\'' . substr($indexes[0],1) . '\') ? ' . substr($indexes[0],1) . ' : null'; + $compiled_ref = '(defined(\'' . substr($indexes[0],1) . '\') ? ' . substr($indexes[0],1) . ' : null)'; break; default: diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index 2dc16162..e3a465be 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -1418,6 +1418,7 @@ class Smarty } } else if ($resource_type != 'file') { $readable = true; + $template_source = null; $resource_func = $this->_plugins['resource'][$resource_type][0][0]; $readable = $resource_func($resource_name, $template_source, $this); } diff --git a/libs/Smarty_Compiler.class.php b/libs/Smarty_Compiler.class.php index 975d3402..8bfc98b5 100644 --- a/libs/Smarty_Compiler.class.php +++ b/libs/Smarty_Compiler.class.php @@ -1086,7 +1086,7 @@ class Smarty_Compiler extends Smarty { preg_match_all('/(?> ' . $this->_obj_call_regexp . '(?:' . $this->_mod_regexp . '*) | # valid object call ' . $this->_var_regexp . '(?:' . $this->_mod_regexp . '*) | # var or quoted string - \-?\d+(?:\.\d+)?|\.\d+|!==|<=>|==|!=|<=|>=|\&\&|\|\||\(|\)|,|\!|\^|=|\&|\~|<|>|\||\%|\+|\-|\/|\* | # valid non-word token + \-?\d+(?:\.\d+)?|\.\d+|!==|<=>|===|==|!=|<=|>=|\&\&|\|\||\(|\)|,|\!|\^|=|\&|\~|<|>|\||\%|\+|\-|\/|\*|\@ | # valid non-word token \b\w+\b | # valid word token \S+ # anything else )/x', $tag_args, $match); @@ -1110,6 +1110,7 @@ class Smarty_Compiler extends Smarty { case '%': case '!==': case '==': + case '===': case '>': case '<': case '!=': @@ -1127,6 +1128,7 @@ class Smarty_Compiler extends Smarty { case '-': case '*': case '/': + case '@': break; case 'eq': @@ -1346,7 +1348,7 @@ class Smarty_Compiler extends Smarty { $token = true; } else if (preg_match('!^(off|no|false)$!', $token)) { $token = false; - } else if (preg_match('!^[\w\.-]+$!', $token)) { + } else if ($quote && preg_match('!^[\w\.-]+$!', $token)) { /* If the token is just a string, we double-quote it. */ $token = '"'.$token.'"'; @@ -1403,7 +1405,7 @@ class Smarty_Compiler extends Smarty { if(preg_match('!^(' . $this->_obj_call_regexp . '|' . $this->_dvar_regexp . ')(?:' . $this->_mod_regexp . '*)$!', $val)) { // $ variable or object - return $this->_parse_var($val, $tag_attrs); + return $this->_parse_var($val); } elseif(preg_match('!^' . $this->_db_qstr_regexp . '(?:' . $this->_mod_regexp . '*)$!', $val)) { // double quoted text @@ -1778,7 +1780,7 @@ class Smarty_Compiler extends Smarty { case 'const': array_shift($indexes); - $compiled_ref = 'defined(\'' . substr($indexes[0],1) . '\') ? ' . substr($indexes[0],1) . ' : null'; + $compiled_ref = '(defined(\'' . substr($indexes[0],1) . '\') ? ' . substr($indexes[0],1) . ' : null)'; break; default: