diff --git a/change_log.txt b/change_log.txt index 5fd4bf9c..2bbe3879 100644 --- a/change_log.txt +++ b/change_log.txt @@ -1,4 +1,7 @@  ===== 3.1.24.dev ===== (xx.xx.2015) + 19.05.2015 + - bugfix compiler did overwrite existing variable value when setting the nocache attribute https://github.com/smarty-php/smarty/issues/39 + 18.05.2015 - improvement introduce shortcuts in lexer/parser rules for most frequent terms for higher compilation speed diff --git a/libs/sysplugins/smarty_internal_compile_if.php b/libs/sysplugins/smarty_internal_compile_if.php index 71d3d4af..d4fd30e9 100644 --- a/libs/sysplugins/smarty_internal_compile_if.php +++ b/libs/sysplugins/smarty_internal_compile_if.php @@ -42,9 +42,14 @@ class Smarty_Internal_Compile_If extends Smarty_Internal_CompileBase $_nocache = ',true'; // create nocache var to make it know for further compiling if (is_array($parameter['if condition']['var'])) { - $compiler->template->tpl_vars[trim($parameter['if condition']['var']['var'], "'")] = new Smarty_Variable(null, true); + $var = trim($parameter['if condition']['var']['var'], "'"); } else { - $compiler->template->tpl_vars[trim($parameter['if condition']['var'], "'")] = new Smarty_Variable(null, true); + $var = trim($parameter['if condition']['var'], "'"); + } + if (isset($compiler->template->tpl_vars[$var])) { + $compiler->template->tpl_vars[$var]->nocache = true; + } else { + $compiler->template->tpl_vars[$var] = new Smarty_Variable(null, true); } } else { $_nocache = ''; @@ -124,9 +129,14 @@ class Smarty_Internal_Compile_Elseif extends Smarty_Internal_CompileBase $_nocache = ',true'; // create nocache var to make it know for further compiling if (is_array($parameter['if condition']['var'])) { - $compiler->template->tpl_vars[trim($parameter['if condition']['var']['var'], "'")] = new Smarty_Variable(null, true); + $var = trim($parameter['if condition']['var']['var'], "'"); } else { - $compiler->template->tpl_vars[trim($parameter['if condition']['var'], "'")] = new Smarty_Variable(null, true); + $var = trim($parameter['if condition']['var'], "'"); + } + if (isset($compiler->template->tpl_vars[$var])) { + $compiler->template->tpl_vars[$var]->nocache = true; + } else { + $compiler->template->tpl_vars[$var] = new Smarty_Variable(null, true); } } else { $_nocache = ''; diff --git a/libs/sysplugins/smarty_internal_compile_insert.php b/libs/sysplugins/smarty_internal_compile_insert.php index 659b3f12..57f27350 100644 --- a/libs/sysplugins/smarty_internal_compile_insert.php +++ b/libs/sysplugins/smarty_internal_compile_insert.php @@ -68,7 +68,12 @@ class Smarty_Internal_Compile_Insert extends Smarty_Internal_CompileBase // output will be stored in a smarty variable instead of being displayed $_assign = $_attr['assign']; // create variable to make sure that the compiler knows about its nocache status - $compiler->template->tpl_vars[trim($_attr['assign'], "'")] = new Smarty_Variable(null, true); + $var = trim($_attr['assign'], "'"); + if (isset($compiler->template->tpl_vars[$var])) { + $compiler->template->tpl_vars[$var]->nocache = true; + } else { + $compiler->template->tpl_vars[$var] = new Smarty_Variable(null, true); + } } if (isset($_attr['script'])) { // script which must be included diff --git a/libs/sysplugins/smarty_internal_compile_while.php b/libs/sysplugins/smarty_internal_compile_while.php index b73602f3..6a6fb3ef 100644 --- a/libs/sysplugins/smarty_internal_compile_while.php +++ b/libs/sysplugins/smarty_internal_compile_while.php @@ -42,9 +42,14 @@ class Smarty_Internal_Compile_While extends Smarty_Internal_CompileBase $_nocache = ',true'; // create nocache var to make it know for further compiling if (is_array($parameter['if condition']['var'])) { - $compiler->template->tpl_vars[trim($parameter['if condition']['var']['var'], "'")] = new Smarty_Variable(null, true); + $var = trim($parameter['if condition']['var']['var'], "'"); } else { - $compiler->template->tpl_vars[trim($parameter['if condition']['var'], "'")] = new Smarty_Variable(null, true); + $var = trim($parameter['if condition']['var'], "'"); + } + if (isset($compiler->template->tpl_vars[$var])) { + $compiler->template->tpl_vars[$var]->nocache = true; + } else { + $compiler->template->tpl_vars[$var] = new Smarty_Variable(null, true); } } else { $_nocache = '';