From 450e15dd8e89ddb7b0e6b5bd1f06be9516736b8e Mon Sep 17 00:00:00 2001 From: mohrt Date: Wed, 15 Jan 2003 15:23:13 +0000 Subject: [PATCH] fix if statement syntax for negative integers, fix issue with directories named '0' --- NEWS | 1 + Smarty.class.php | 6 ++-- Smarty_Compiler.class.php | 52 ++++++++++++++++++++-------------- libs/Smarty.class.php | 6 ++-- libs/Smarty_Compiler.class.php | 52 ++++++++++++++++++++-------------- 5 files changed, 67 insertions(+), 50 deletions(-) diff --git a/NEWS b/NEWS index faa70e07..14c36559 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,4 @@ + - fixed bug with directories named '0' (Frank Bauer, Monte) - add javascript parameter to escape modifier (Monte) - added correct line numbers to syntax error messages in compiler (Monte) diff --git a/Smarty.class.php b/Smarty.class.php index 01e55d95..7526842d 100644 --- a/Smarty.class.php +++ b/Smarty.class.php @@ -466,8 +466,8 @@ class Smarty function unregister_outputfilter($function) { unset($this->_plugins['outputfilter'][$function]); - } - + } + /*======================================================================*\ Function: load_filter() Purpose: load a filter of specified type and name @@ -1605,7 +1605,7 @@ function _run_insert_handler($args) if($handle = @opendir($dirname)) { - while ($entry = readdir($handle)) { + while (null != ($entry = readdir($handle))) { if ($entry != '.' && $entry != '..') { if (@is_dir($dirname . DIR_SEP . $entry)) { $this->_rmdir($dirname . DIR_SEP . $entry, $level + 1, $exp_time); diff --git a/Smarty_Compiler.class.php b/Smarty_Compiler.class.php index 5e12f7fc..b213a642 100644 --- a/Smarty_Compiler.class.php +++ b/Smarty_Compiler.class.php @@ -106,7 +106,8 @@ class Smarty_Compiler extends Smarty { $this->_svar_regexp = '\%\w+\.\w+\%'; // matches all valid variables (no quotes, no modifiers) - $this->_avar_regexp = '(?:' . $this->_dvar_regexp . '|' . $this->_cvar_regexp . '|' . $this->_svar_regexp . ')'; + $this->_avar_regexp = '(?:' . $this->_dvar_regexp . '|' + . $this->_cvar_regexp . '|' . $this->_svar_regexp . ')'; // matches valid modifier syntax: // |foo @@ -116,7 +117,8 @@ class Smarty_Compiler extends Smarty { // |foo:"bar":$foobar // |foo|bar // |foo - $this->_mod_regexp = '(?:\|@?\w+(?::(?>\w+|' . $this->_avar_regexp . '|' . $this->_qstr_regexp .'))*)'; + $this->_mod_regexp = '(?:\|@?\w+(?::(?>\w+|' + . $this->_avar_regexp . '|' . $this->_qstr_regexp .'))*)'; // matches valid variable syntax: // $foo @@ -164,7 +166,8 @@ class Smarty_Compiler extends Smarty { // "text" // "text"|bar // $foo->bar() - $this->_param_regexp = '(?:\s*(?:' . $this->_obj_call_regexp . '|' . $this->_var_regexp . '|\w+)(?>' . $this->_mod_regexp . '*)\s*)'; + $this->_param_regexp = '(?:\s*(?:' . $this->_obj_call_regexp . '|' + . $this->_var_regexp . '|\w+)(?>' . $this->_mod_regexp . '*)\s*)'; // matches valid parenthesised function parameters: // @@ -180,7 +183,8 @@ class Smarty_Compiler extends Smarty { // foo_bar($foo) // _foo_bar($foo,"bar") // foo123($foo,$foo->bar(),"foo") - $this->_func_call_regexp = '(?:' . $this->_func_regexp . '\s*(?:' . $this->_parenth_param_regexp . '))'; + $this->_func_call_regexp = '(?:' . $this->_func_regexp . '\s*(?:' + . $this->_parenth_param_regexp . '))'; } @@ -969,13 +973,13 @@ 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+|!==|<=>|==|!=|<=|>=|\&\&|\|\||\(|\)|,|\!|\^|=|<|>|\||\% | # valid non-word token + \-?\d+|!==|<=>|==|!=|<=|>=|\&\&|\|\||\(|\)|,|\!|\^|=|<|>|\||\% | # valid non-word token \b\w+\b | # valid word token \S+ # anything else )/x', $tag_args, $match); $tokens = $match[0]; - + // make sure we have balanced parenthesis $token_count = array_count_values($tokens); if(isset($token_count['(']) && $token_count['('] != $token_count[')']) { @@ -989,64 +993,72 @@ class Smarty_Compiler extends Smarty { $token = &$tokens[$i]; switch ($token) { - case 'eq': + case '!': + case '%': + case '!==': case '==': + case '>': + case '<': + case '!=': + case '<=': + case '>=': + case '&&': + case '||': + case '|': + case '^': + case '&': + case '~': + case ')': + case ',': + break; + + case 'eq': $token = '=='; break; case 'ne': case 'neq': - case '!=': - case '!==': $token = '!='; break; case 'lt': - case '<': $token = '<'; break; case 'le': case 'lte': - case '<=': $token = '<='; break; case 'gt': - case '>': $token = '>'; break; case 'ge': case 'gte': - case '>=': $token = '>='; break; case 'and': - case '&&': $token = '&&'; break; case 'or': - case '||': $token = '||'; break; case 'not': - case '!': $token = '!'; break; case 'mod': - case '%': $token = '%'; break; case '(': array_push($is_arg_stack, $i); break; - + case 'is': /* If last token was a ')', we operate on the parenthesized expression. The start of the expression is on the stack. @@ -1073,10 +1085,6 @@ class Smarty_Compiler extends Smarty { current position for the next iteration. */ $i = $is_arg_start; break; - - case ')': - case ',': - break; default: if(preg_match('!^' . $this->_func_regexp . '$!', $token) ) { diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index 01e55d95..7526842d 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -466,8 +466,8 @@ class Smarty function unregister_outputfilter($function) { unset($this->_plugins['outputfilter'][$function]); - } - + } + /*======================================================================*\ Function: load_filter() Purpose: load a filter of specified type and name @@ -1605,7 +1605,7 @@ function _run_insert_handler($args) if($handle = @opendir($dirname)) { - while ($entry = readdir($handle)) { + while (null != ($entry = readdir($handle))) { if ($entry != '.' && $entry != '..') { if (@is_dir($dirname . DIR_SEP . $entry)) { $this->_rmdir($dirname . DIR_SEP . $entry, $level + 1, $exp_time); diff --git a/libs/Smarty_Compiler.class.php b/libs/Smarty_Compiler.class.php index 5e12f7fc..b213a642 100644 --- a/libs/Smarty_Compiler.class.php +++ b/libs/Smarty_Compiler.class.php @@ -106,7 +106,8 @@ class Smarty_Compiler extends Smarty { $this->_svar_regexp = '\%\w+\.\w+\%'; // matches all valid variables (no quotes, no modifiers) - $this->_avar_regexp = '(?:' . $this->_dvar_regexp . '|' . $this->_cvar_regexp . '|' . $this->_svar_regexp . ')'; + $this->_avar_regexp = '(?:' . $this->_dvar_regexp . '|' + . $this->_cvar_regexp . '|' . $this->_svar_regexp . ')'; // matches valid modifier syntax: // |foo @@ -116,7 +117,8 @@ class Smarty_Compiler extends Smarty { // |foo:"bar":$foobar // |foo|bar // |foo - $this->_mod_regexp = '(?:\|@?\w+(?::(?>\w+|' . $this->_avar_regexp . '|' . $this->_qstr_regexp .'))*)'; + $this->_mod_regexp = '(?:\|@?\w+(?::(?>\w+|' + . $this->_avar_regexp . '|' . $this->_qstr_regexp .'))*)'; // matches valid variable syntax: // $foo @@ -164,7 +166,8 @@ class Smarty_Compiler extends Smarty { // "text" // "text"|bar // $foo->bar() - $this->_param_regexp = '(?:\s*(?:' . $this->_obj_call_regexp . '|' . $this->_var_regexp . '|\w+)(?>' . $this->_mod_regexp . '*)\s*)'; + $this->_param_regexp = '(?:\s*(?:' . $this->_obj_call_regexp . '|' + . $this->_var_regexp . '|\w+)(?>' . $this->_mod_regexp . '*)\s*)'; // matches valid parenthesised function parameters: // @@ -180,7 +183,8 @@ class Smarty_Compiler extends Smarty { // foo_bar($foo) // _foo_bar($foo,"bar") // foo123($foo,$foo->bar(),"foo") - $this->_func_call_regexp = '(?:' . $this->_func_regexp . '\s*(?:' . $this->_parenth_param_regexp . '))'; + $this->_func_call_regexp = '(?:' . $this->_func_regexp . '\s*(?:' + . $this->_parenth_param_regexp . '))'; } @@ -969,13 +973,13 @@ 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+|!==|<=>|==|!=|<=|>=|\&\&|\|\||\(|\)|,|\!|\^|=|<|>|\||\% | # valid non-word token + \-?\d+|!==|<=>|==|!=|<=|>=|\&\&|\|\||\(|\)|,|\!|\^|=|<|>|\||\% | # valid non-word token \b\w+\b | # valid word token \S+ # anything else )/x', $tag_args, $match); $tokens = $match[0]; - + // make sure we have balanced parenthesis $token_count = array_count_values($tokens); if(isset($token_count['(']) && $token_count['('] != $token_count[')']) { @@ -989,64 +993,72 @@ class Smarty_Compiler extends Smarty { $token = &$tokens[$i]; switch ($token) { - case 'eq': + case '!': + case '%': + case '!==': case '==': + case '>': + case '<': + case '!=': + case '<=': + case '>=': + case '&&': + case '||': + case '|': + case '^': + case '&': + case '~': + case ')': + case ',': + break; + + case 'eq': $token = '=='; break; case 'ne': case 'neq': - case '!=': - case '!==': $token = '!='; break; case 'lt': - case '<': $token = '<'; break; case 'le': case 'lte': - case '<=': $token = '<='; break; case 'gt': - case '>': $token = '>'; break; case 'ge': case 'gte': - case '>=': $token = '>='; break; case 'and': - case '&&': $token = '&&'; break; case 'or': - case '||': $token = '||'; break; case 'not': - case '!': $token = '!'; break; case 'mod': - case '%': $token = '%'; break; case '(': array_push($is_arg_stack, $i); break; - + case 'is': /* If last token was a ')', we operate on the parenthesized expression. The start of the expression is on the stack. @@ -1073,10 +1085,6 @@ class Smarty_Compiler extends Smarty { current position for the next iteration. */ $i = $is_arg_start; break; - - case ')': - case ',': - break; default: if(preg_match('!^' . $this->_func_regexp . '$!', $token) ) {