few more fixes, spaces around function parameters

This commit is contained in:
mohrt
2002-12-20 17:25:01 +00:00
parent 397ead161f
commit 70a51d1674
2 changed files with 30 additions and 22 deletions

View File

@@ -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,7 +947,6 @@ class Smarty_Compiler extends Smarty {
return $output;
}
/*======================================================================*\
Function: _compile_if_tag
Purpose: Compile {if ...} tag
@@ -961,7 +960,8 @@ class Smarty_Compiler extends Smarty {
' . $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];
@@ -1063,6 +1063,7 @@ class Smarty_Compiler extends Smarty {
default:
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;
}

View File

@@ -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,7 +947,6 @@ class Smarty_Compiler extends Smarty {
return $output;
}
/*======================================================================*\
Function: _compile_if_tag
Purpose: Compile {if ...} tag
@@ -961,7 +960,8 @@ class Smarty_Compiler extends Smarty {
' . $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];
@@ -1063,6 +1063,7 @@ class Smarty_Compiler extends Smarty {
default:
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;
}