summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoruwetews <uwe.tews@googlemail.com>2016-09-15 02:56:34 +0200
committeruwetews <uwe.tews@googlemail.com>2016-09-15 02:56:34 +0200
commit424dca6d24f98e72db0e57369c4739e97b2ecaef (patch)
treeb46cac8234f3e5a150ddce3dbcca8c89cd75dea8
parent44189a7531f8c87c3d6069fd6716acce1e6a7627 (diff)
downloadsmarty-424dca6d24f98e72db0e57369c4739e97b2ecaef.tar.gz
smarty-424dca6d24f98e72db0e57369c4739e97b2ecaef.tar.bz2
smarty-424dca6d24f98e72db0e57369c4739e97b2ecaef.zip
- bugfix assigning a variable in if condition by function like {if $value = array_shift($array)} the function got called twice https://github.com/smarty-php/smarty/issues/291
-rw-r--r--change_log.txt3
-rw-r--r--libs/Smarty.class.php2
-rw-r--r--libs/sysplugins/smarty_internal_compile_if.php37
-rw-r--r--libs/sysplugins/smarty_internal_compile_while.php10
4 files changed, 30 insertions, 22 deletions
diff --git a/change_log.txt b/change_log.txt
index f9e07ccb..c60f1d52 100644
--- a/change_log.txt
+++ b/change_log.txt
@@ -1,4 +1,7 @@
===== 3.1.31-dev ===== (xx.xx.xx)
+ 15.09.2016
+ - bugfix assigning a variable in if condition by function like {if $value = array_shift($array)} the function got called twice https://github.com/smarty-php/smarty/issues/291
+
11.09.2016
- improvement {math} misleading E_USER_WARNING messages when parameter value = null https://github.com/smarty-php/smarty/issues/288
- improvement move often used code snippets into methods
diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php
index 4d3dce71..6816b7dc 100644
--- a/libs/Smarty.class.php
+++ b/libs/Smarty.class.php
@@ -114,7 +114,7 @@ class Smarty extends Smarty_Internal_TemplateBase
/**
* smarty version
*/
- const SMARTY_VERSION = '3.1.31-dev/18';
+ const SMARTY_VERSION = '3.1.31-dev/19';
/**
* define variable scopes
diff --git a/libs/sysplugins/smarty_internal_compile_if.php b/libs/sysplugins/smarty_internal_compile_if.php
index f50750ae..84c39df0 100644
--- a/libs/sysplugins/smarty_internal_compile_if.php
+++ b/libs/sysplugins/smarty_internal_compile_if.php
@@ -39,13 +39,13 @@ class Smarty_Internal_Compile_If extends Smarty_Internal_CompileBase
}
if (is_array($parameter[ 'if condition' ])) {
+ if (is_array($parameter[ 'if condition' ][ 'var' ])) {
+ $var = $parameter[ 'if condition' ][ 'var' ][ 'var' ];
+ } else {
+ $var = $parameter[ 'if condition' ][ 'var' ];
+ }
if ($compiler->nocache) {
// create nocache var to make it know for further compiling
- if (is_array($parameter[ 'if condition' ][ 'var' ])) {
- $var = $parameter[ 'if condition' ][ 'var' ][ 'var' ];
- } else {
- $var = $parameter[ 'if condition' ][ 'var' ];
- }
$compiler->setNocacheInVariable($var);
}
$assignCompiler = new Smarty_Internal_Compile_Assign();
@@ -59,7 +59,9 @@ class Smarty_Internal_Compile_If extends Smarty_Internal_CompileBase
$assignAttr[][ 'var' ] = $parameter[ 'if condition' ][ 'var' ];
$_output = $assignCompiler->compile($assignAttr, $compiler, array());
}
- $_output .= "<?php if (" . $parameter[ 'if condition' ][ 'value' ] . ") {?>";
+ $_output .= "<?php if (\$_smarty_tpl->tpl_vars[{$var}]->value" .
+ (isset($parameter[ 'if condition' ][ 'var' ][ 'smarty_internal_index' ]) ?
+ $parameter[ 'if condition' ][ 'var' ][ 'smarty_internal_index' ] : '') . ") {?>";
return $_output;
} else {
return "<?php if ({$parameter['if condition']}) {?>";
@@ -123,15 +125,16 @@ class Smarty_Internal_Compile_Elseif extends Smarty_Internal_CompileBase
}
$assignCode = '';
+ $var = '';
if (is_array($parameter[ 'if condition' ])) {
$condition_by_assign = true;
+ if (is_array($parameter[ 'if condition' ][ 'var' ])) {
+ $var = $parameter[ 'if condition' ][ 'var' ][ 'var' ];
+ } else {
+ $var = $parameter[ 'if condition' ][ 'var' ];
+ }
if ($compiler->nocache) {
// create nocache var to make it know for further compiling
- if (is_array($parameter[ 'if condition' ][ 'var' ])) {
- $var = $parameter[ 'if condition' ][ 'var' ][ 'var' ];
- } else {
- $var = $parameter[ 'if condition' ][ 'var' ];
- }
$compiler->setNocacheInVariable($var);
}
$assignCompiler = new Smarty_Internal_Compile_Assign();
@@ -154,8 +157,10 @@ class Smarty_Internal_Compile_Elseif extends Smarty_Internal_CompileBase
if ($condition_by_assign) {
$this->openTag($compiler, 'elseif', array($nesting + 1, $compiler->tag_nocache));
$_output = $compiler->appendCode("<?php } else {\n?>", $assignCode);
- return $compiler->appendCode($_output,
- "<?php if (" . $parameter[ 'if condition' ][ 'value' ] . ") {\n?>");
+ return $compiler->appendCode($_output, "<?php if (\$_smarty_tpl->tpl_vars[{$var}]->value" .
+ (isset($parameter[ 'if condition' ][ 'var' ][ 'smarty_internal_index' ]) ?
+ $parameter[ 'if condition' ][ 'var' ][ 'smarty_internal_index' ] :
+ '') . ") {?>");
} else {
$this->openTag($compiler, 'elseif', array($nesting, $compiler->tag_nocache));
return "<?php } elseif ({$parameter['if condition']}) {?>";
@@ -165,8 +170,10 @@ class Smarty_Internal_Compile_Elseif extends Smarty_Internal_CompileBase
$this->openTag($compiler, 'elseif', array($nesting + 1, $compiler->tag_nocache));
if ($condition_by_assign) {
$_output = $compiler->appendCode($_output, $assignCode);
- return $compiler->appendCode($_output,
- "<?php if (" . $parameter[ 'if condition' ][ 'value' ] . ") {\n?>");
+ return $compiler->appendCode($_output, "<?php if (\$_smarty_tpl->tpl_vars[{$var}]->value" .
+ (isset($parameter[ 'if condition' ][ 'var' ][ 'smarty_internal_index' ]) ?
+ $parameter[ 'if condition' ][ 'var' ][ 'smarty_internal_index' ] :
+ '') . ") {?>");
} else {
return $compiler->appendCode($_output, "<?php if ({$parameter['if condition']}) {?>");
}
diff --git a/libs/sysplugins/smarty_internal_compile_while.php b/libs/sysplugins/smarty_internal_compile_while.php
index 30d83095..6025798c 100644
--- a/libs/sysplugins/smarty_internal_compile_while.php
+++ b/libs/sysplugins/smarty_internal_compile_while.php
@@ -41,7 +41,6 @@ class Smarty_Internal_Compile_While extends Smarty_Internal_CompileBase
$compiler->nocache = $compiler->nocache | $compiler->tag_nocache;
if (is_array($parameter[ 'if condition' ])) {
if ($compiler->nocache) {
- $_nocache = ',true';
// create nocache var to make it know for further compiling
if (is_array($parameter[ 'if condition' ][ 'var' ])) {
$var = $parameter[ 'if condition' ][ 'var' ][ 'var' ];
@@ -49,20 +48,19 @@ class Smarty_Internal_Compile_While extends Smarty_Internal_CompileBase
$var = $parameter[ 'if condition' ][ 'var' ];
}
$compiler->setNocacheInVariable($var);
- } else {
- $_nocache = '';
}
+ $prefixVar = $compiler->getNewPrefixVariable();
$assignCompiler = new Smarty_Internal_Compile_Assign();
$assignAttr = array();
- $assignAttr[][ 'value' ] = $parameter[ 'if condition' ][ 'value' ];
+ $assignAttr[][ 'value' ] = "{$prefixVar}";
if (is_array($parameter[ 'if condition' ][ 'var' ])) {
$assignAttr[][ 'var' ] = $parameter[ 'if condition' ][ 'var' ][ 'var' ];
- $_output = "<?php while (" . $parameter[ 'if condition' ][ 'value' ] . ") {?>";
+ $_output = "<?php while ({$prefixVar} = " . $parameter[ 'if condition' ][ 'value' ] . ") {?>";
$_output .= $assignCompiler->compile($assignAttr, $compiler,
array('smarty_internal_index' => $parameter[ 'if condition' ][ 'var' ][ 'smarty_internal_index' ]));
} else {
$assignAttr[][ 'var' ] = $parameter[ 'if condition' ][ 'var' ];
- $_output = "<?php while (" . $parameter[ 'if condition' ][ 'value' ] . ") {?>";
+ $_output = "<?php while ({$prefixVar} = " . $parameter[ 'if condition' ][ 'value' ] . ") {?>";
$_output .= $assignCompiler->compile($assignAttr, $compiler, array());
}