From d3e71dabb62f3283244b018abc86c5bc5a465b97 Mon Sep 17 00:00:00 2001 From: "uwe.tews@googlemail.com" Date: Tue, 1 Nov 2011 20:27:53 +0000 Subject: [PATCH] - bugfix {if} and {while} tags without condition did not throw a SmartyCompilerException (Issue #57) --- change_log.txt | 3 + .../sysplugins/smarty_internal_compile_if.php | 123 ++++++++++-------- .../smarty_internal_compile_while.php | 4 + 3 files changed, 73 insertions(+), 57 deletions(-) diff --git a/change_log.txt b/change_log.txt index 9462ceb4..ccecf90a 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,4 +1,7 @@ ===== trunk ===== +01.11.2011 +- bugfix {if} and {while} tags without condition did not throw a SmartyCompilerException (Issue #57) + 22.10.2011 - bugfix smarty_mb_from_unicode() would not decode unicode-points properly - bugfix use catch Exception instead UnexpectedValueException in diff --git a/libs/sysplugins/smarty_internal_compile_if.php b/libs/sysplugins/smarty_internal_compile_if.php index 98e8ac91..8794b014 100644 --- a/libs/sysplugins/smarty_internal_compile_if.php +++ b/libs/sysplugins/smarty_internal_compile_if.php @@ -1,30 +1,30 @@ openTag($compiler, 'if', array(1, $compiler->nocache)); // must whole block be nocache ? $compiler->nocache = $compiler->nocache | $compiler->tag_nocache; + + if (!array_key_exists("if condition",$parameter)) { + $compiler->trigger_template_error("missing if condition", $compiler->lex->taglineno); + } + if (is_array($parameter['if condition'])) { if ($compiler->nocache) { $_nocache = ',true'; @@ -60,21 +65,21 @@ class Smarty_Internal_Compile_If extends Smarty_Internal_CompileBase { } /** - * Smarty Internal Plugin Compile Else Class - * - * @package Smarty - * @subpackage Compiler - */ +* Smarty Internal Plugin Compile Else Class +* +* @package Smarty +* @subpackage Compiler +*/ class Smarty_Internal_Compile_Else extends Smarty_Internal_CompileBase { /** - * Compiles code for the {else} tag - * - * @param array $args array with attributes from parser - * @param object $compiler compiler object - * @param array $parameter array with compilation parameter - * @return string compiled code - */ + * Compiles code for the {else} tag + * + * @param array $args array with attributes from parser + * @param object $compiler compiler object + * @param array $parameter array with compilation parameter + * @return string compiled code + */ public function compile($args, $compiler, $parameter) { list($nesting, $compiler->tag_nocache) = $this->closeTag($compiler, array('if', 'elseif')); @@ -86,21 +91,21 @@ class Smarty_Internal_Compile_Else extends Smarty_Internal_CompileBase { } /** - * Smarty Internal Plugin Compile ElseIf Class - * - * @package Smarty - * @subpackage Compiler - */ +* Smarty Internal Plugin Compile ElseIf Class +* +* @package Smarty +* @subpackage Compiler +*/ class Smarty_Internal_Compile_Elseif extends Smarty_Internal_CompileBase { /** - * Compiles code for the {elseif} tag - * - * @param array $args array with attributes from parser - * @param object $compiler compiler object - * @param array $parameter array with compilation parameter - * @return string compiled code - */ + * Compiles code for the {elseif} tag + * + * @param array $args array with attributes from parser + * @param object $compiler compiler object + * @param array $parameter array with compilation parameter + * @return string compiled code + */ public function compile($args, $compiler, $parameter) { // check and get attributes @@ -108,6 +113,10 @@ class Smarty_Internal_Compile_Elseif extends Smarty_Internal_CompileBase { list($nesting, $compiler->tag_nocache) = $this->closeTag($compiler, array('if', 'elseif')); + if (!array_key_exists("if condition",$parameter)) { + $compiler->trigger_template_error("missing elseif condition", $compiler->lex->taglineno); + } + if (is_array($parameter['if condition'])) { $condition_by_assign = true; if ($compiler->nocache) { @@ -143,7 +152,7 @@ class Smarty_Internal_Compile_Elseif extends Smarty_Internal_CompileBase { } else { $tmp = ''; foreach ($compiler->prefix_code as $code) - $tmp .= $code; + $tmp .= $code; $compiler->prefix_code = array(); $this->openTag($compiler, 'elseif', array($nesting + 1, $compiler->tag_nocache)); if ($condition_by_assign) { @@ -164,21 +173,21 @@ class Smarty_Internal_Compile_Elseif extends Smarty_Internal_CompileBase { } /** - * Smarty Internal Plugin Compile Ifclose Class - * - * @package Smarty - * @subpackage Compiler - */ +* Smarty Internal Plugin Compile Ifclose Class +* +* @package Smarty +* @subpackage Compiler +*/ class Smarty_Internal_Compile_Ifclose extends Smarty_Internal_CompileBase { /** - * Compiles code for the {/if} tag - * - * @param array $args array with attributes from parser - * @param object $compiler compiler object - * @param array $parameter array with compilation parameter - * @return string compiled code - */ + * Compiles code for the {/if} tag + * + * @param array $args array with attributes from parser + * @param object $compiler compiler object + * @param array $parameter array with compilation parameter + * @return string compiled code + */ public function compile($args, $compiler, $parameter) { // must endblock be nocache? diff --git a/libs/sysplugins/smarty_internal_compile_while.php b/libs/sysplugins/smarty_internal_compile_while.php index 46b6e269..d7d986c3 100644 --- a/libs/sysplugins/smarty_internal_compile_while.php +++ b/libs/sysplugins/smarty_internal_compile_while.php @@ -31,6 +31,10 @@ class Smarty_Internal_Compile_While extends Smarty_Internal_CompileBase { $_attr = $this->getAttributes($compiler, $args); $this->openTag($compiler, 'while', $compiler->nocache); + if (!array_key_exists("if condition",$parameter)) { + $compiler->trigger_template_error("missing while condition", $compiler->lex->taglineno); + } + // maybe nocache because of nocache variables $compiler->nocache = $compiler->nocache | $compiler->tag_nocache; if (is_array($parameter['if condition'])) {