From 5468f140fa591b02a01e85cc9f226164e96bce65 Mon Sep 17 00:00:00 2001 From: Uwe Tews Date: Tue, 19 May 2015 22:47:04 +0200 Subject: [PATCH] - bugfix compiler did overwrite existing variable value when setting the nocache attribute https://github.com/smarty-php/smarty/issues/39 --- change_log.txt | 3 +++ libs/sysplugins/smarty_internal_compile_if.php | 18 ++++++++++++++---- .../smarty_internal_compile_insert.php | 7 ++++++- .../smarty_internal_compile_while.php | 9 +++++++-- 4 files changed, 30 insertions(+), 7 deletions(-) diff --git a/change_log.txt b/change_log.txt index 5fd4bf9c6..2bbe3879c 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 71d3d4afe..d4fd30e9f 100644 --- a/libs/sysplugins/smarty_internal_compile_if.php +++ b/libs/sysplugins/smarty_internal_compile_if.php @@ -42,9 +42,14 @@ public function compile($args, $compiler, $parameter) $_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 @@ public function compile($args, $compiler, $parameter) $_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 { + $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[trim($parameter['if condition']['var'], "'")] = new Smarty_Variable(null, true); + $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 659b3f120..57f273506 100644 --- a/libs/sysplugins/smarty_internal_compile_insert.php +++ b/libs/sysplugins/smarty_internal_compile_insert.php @@ -68,7 +68,12 @@ public function compile($args, $compiler) // 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 b73602f3f..6a6fb3ef1 100644 --- a/libs/sysplugins/smarty_internal_compile_while.php +++ b/libs/sysplugins/smarty_internal_compile_while.php @@ -42,9 +42,14 @@ public function compile($args, $compiler, $parameter) $_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 = '';