From 70a51d16741999955f0cd4a0e64e48e0b4b432fb Mon Sep 17 00:00:00 2001 From: mohrt Date: Fri, 20 Dec 2002 17:25:01 +0000 Subject: [PATCH] few more fixes, spaces around function parameters --- Smarty_Compiler.class.php | 26 +++++++++++++++----------- libs/Smarty_Compiler.class.php | 26 +++++++++++++++----------- 2 files changed, 30 insertions(+), 22 deletions(-) diff --git a/Smarty_Compiler.class.php b/Smarty_Compiler.class.php index ac8705d2..9cacaceb 100644 --- a/Smarty_Compiler.class.php +++ b/Smarty_Compiler.class.php @@ -142,7 +142,7 @@ class Smarty_Compiler extends Smarty { // matches valid function name: // foo123 // _foo_bar - $this->_func_regexp = '[a-zA-Z_]\w*'; + $this->_func_regexp = '[a-zA-Z_]\w*'; // matches valid parameter values: // true @@ -153,7 +153,7 @@ class Smarty_Compiler extends Smarty { // "text" // "text"|bar // $foo->bar() - $this->_param_regexp = '(?:(?:' . $this->_obj_call_regexp . '|' . $this->_var_regexp . '|\w+)' . $this->_mod_regexp . ')'; + $this->_param_regexp = '(?:\s*(?:' . $this->_obj_call_regexp . '|' . $this->_var_regexp . '|\w+)' . $this->_mod_regexp . '\s*)'; // matches valid parenthesised function parameters: // @@ -161,14 +161,14 @@ class Smarty_Compiler extends Smarty { // $foo, $bar, "text" // $foo|bar, "foo"|bar, $foo->bar($foo)|bar $this->_parenth_param_regexp = '(?:\((?:' . $this->_param_regexp - . '(?:\s*,\s*(?:' . $this->_param_regexp . '))*)?\))'; + . '(?:,(?:' . $this->_param_regexp . '))*)?\))'; // matches valid function call: // foo() // foo_bar($foo) // _foo_bar($foo,"bar") // foo123($foo,$foo->bar(),"foo") - $this->_func_call_regexp = '(?:' . $this->_func_regexp . '(?:' . $this->_parenth_param_regexp . '))'; + $this->_func_call_regexp = '(?:' . $this->_func_regexp . '\s*(?:' . $this->_parenth_param_regexp . '))'; } @@ -947,25 +947,25 @@ class Smarty_Compiler extends Smarty { return $output; } - /*======================================================================*\ Function: _compile_if_tag Purpose: Compile {if ...} tag \*======================================================================*/ function _compile_if_tag($tag_args, $elseif = false) { - + /* Tokenize args for 'if' tag. */ preg_match_all('/(?> ' . $this->_func_call_regexp . ' | # valid function call ' . $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 - even|odd|neq|lte|gte|and|not|mod|eq|ne|lt|le|gt|ge|or|is|div|by|is # valid word token + \b(even|odd|neq|lte|gte|and|not|mod|div|eq|ne|lt|le|gt|ge|or|is|by)\b | # valid word token + \S+ # anything else )/x', $tag_args, $match); $tokens = $match[0]; - + $is_arg_stack = array(); for ($i = 0; $i < count($tokens); $i++) { @@ -1062,7 +1062,8 @@ class Smarty_Compiler extends Smarty { break; default: - if(preg_match('!^(' . $this->_func_regexp . ')(' . $this->_parenth_param_regexp . ')$!', $token, $match)) { + if(preg_match('!^(' . $this->_func_regexp . ')(' . $this->_parenth_param_regexp . ')$!', $token, $match)) { + // function call if($this->security && $i+1 < count($tokens) && $tokens[$i+1] == '(' && @@ -1232,6 +1233,9 @@ class Smarty_Compiler extends Smarty { \*======================================================================*/ function _parse_var_props($val) { + + $val = trim($val); + if(preg_match('!^(' . $this->_obj_call_regexp . '|' . $this->_dvar_regexp . ')' . $this->_mod_regexp . '$!', $val)) { // $ variable or object return $this->_parse_var($val); @@ -1263,7 +1267,7 @@ class Smarty_Compiler extends Smarty { } elseif(!in_array($val, $this->_permitted_tokens) && !is_numeric($val)) { // literal string - return '"' . $val .'"'; + return $this->_expand_quoted_text('"' . $val .'"'); } return $val; } @@ -1309,7 +1313,7 @@ class Smarty_Compiler extends Smarty { $indexes = $match[0]; $var_name = array_shift($indexes); - + /* Handle $smarty.* variable references as a special case. */ if ($var_name == 'smarty') { /* diff --git a/libs/Smarty_Compiler.class.php b/libs/Smarty_Compiler.class.php index ac8705d2..9cacaceb 100644 --- a/libs/Smarty_Compiler.class.php +++ b/libs/Smarty_Compiler.class.php @@ -142,7 +142,7 @@ class Smarty_Compiler extends Smarty { // matches valid function name: // foo123 // _foo_bar - $this->_func_regexp = '[a-zA-Z_]\w*'; + $this->_func_regexp = '[a-zA-Z_]\w*'; // matches valid parameter values: // true @@ -153,7 +153,7 @@ class Smarty_Compiler extends Smarty { // "text" // "text"|bar // $foo->bar() - $this->_param_regexp = '(?:(?:' . $this->_obj_call_regexp . '|' . $this->_var_regexp . '|\w+)' . $this->_mod_regexp . ')'; + $this->_param_regexp = '(?:\s*(?:' . $this->_obj_call_regexp . '|' . $this->_var_regexp . '|\w+)' . $this->_mod_regexp . '\s*)'; // matches valid parenthesised function parameters: // @@ -161,14 +161,14 @@ class Smarty_Compiler extends Smarty { // $foo, $bar, "text" // $foo|bar, "foo"|bar, $foo->bar($foo)|bar $this->_parenth_param_regexp = '(?:\((?:' . $this->_param_regexp - . '(?:\s*,\s*(?:' . $this->_param_regexp . '))*)?\))'; + . '(?:,(?:' . $this->_param_regexp . '))*)?\))'; // matches valid function call: // foo() // foo_bar($foo) // _foo_bar($foo,"bar") // foo123($foo,$foo->bar(),"foo") - $this->_func_call_regexp = '(?:' . $this->_func_regexp . '(?:' . $this->_parenth_param_regexp . '))'; + $this->_func_call_regexp = '(?:' . $this->_func_regexp . '\s*(?:' . $this->_parenth_param_regexp . '))'; } @@ -947,25 +947,25 @@ class Smarty_Compiler extends Smarty { return $output; } - /*======================================================================*\ Function: _compile_if_tag Purpose: Compile {if ...} tag \*======================================================================*/ function _compile_if_tag($tag_args, $elseif = false) { - + /* Tokenize args for 'if' tag. */ preg_match_all('/(?> ' . $this->_func_call_regexp . ' | # valid function call ' . $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 - even|odd|neq|lte|gte|and|not|mod|eq|ne|lt|le|gt|ge|or|is|div|by|is # valid word token + \b(even|odd|neq|lte|gte|and|not|mod|div|eq|ne|lt|le|gt|ge|or|is|by)\b | # valid word token + \S+ # anything else )/x', $tag_args, $match); $tokens = $match[0]; - + $is_arg_stack = array(); for ($i = 0; $i < count($tokens); $i++) { @@ -1062,7 +1062,8 @@ class Smarty_Compiler extends Smarty { break; default: - if(preg_match('!^(' . $this->_func_regexp . ')(' . $this->_parenth_param_regexp . ')$!', $token, $match)) { + if(preg_match('!^(' . $this->_func_regexp . ')(' . $this->_parenth_param_regexp . ')$!', $token, $match)) { + // function call if($this->security && $i+1 < count($tokens) && $tokens[$i+1] == '(' && @@ -1232,6 +1233,9 @@ class Smarty_Compiler extends Smarty { \*======================================================================*/ function _parse_var_props($val) { + + $val = trim($val); + if(preg_match('!^(' . $this->_obj_call_regexp . '|' . $this->_dvar_regexp . ')' . $this->_mod_regexp . '$!', $val)) { // $ variable or object return $this->_parse_var($val); @@ -1263,7 +1267,7 @@ class Smarty_Compiler extends Smarty { } elseif(!in_array($val, $this->_permitted_tokens) && !is_numeric($val)) { // literal string - return '"' . $val .'"'; + return $this->_expand_quoted_text('"' . $val .'"'); } return $val; } @@ -1309,7 +1313,7 @@ class Smarty_Compiler extends Smarty { $indexes = $match[0]; $var_name = array_shift($indexes); - + /* Handle $smarty.* variable references as a special case. */ if ($var_name == 'smarty') { /*