From 62d772e7345192134a62855f4bcf3387387afa78 Mon Sep 17 00:00:00 2001 From: Simon Wisselink Date: Mon, 27 Jan 2020 16:02:02 +0100 Subject: [PATCH] Fixed broken nesting and null handling. --- libs/sysplugins/smarty_internal_compile_foreach.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/libs/sysplugins/smarty_internal_compile_foreach.php b/libs/sysplugins/smarty_internal_compile_foreach.php index 42814582..a68da540 100644 --- a/libs/sysplugins/smarty_internal_compile_foreach.php +++ b/libs/sysplugins/smarty_internal_compile_foreach.php @@ -192,7 +192,7 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_Compile_Private_Fo $this->openTag( $compiler, 'foreach', - array('foreach', $compiler->nocache, $local, $itemVar, empty($itemAttr) ? 0 : 1) + array('foreach', $compiler->nocache, $local, $itemVar, empty($itemAttr) ? 1 : 2) ); // maybe nocache because of nocache variables $compiler->nocache = $compiler->nocache | $compiler->tag_nocache; @@ -220,7 +220,7 @@ class Smarty_Internal_Compile_Foreach extends Smarty_Internal_Compile_Private_Fo $output .= "{$itemVar}->index = -1;\n"; } $output .= "{$itemVar}->do_else = true;\n"; - $output .= "foreach (\$_from as {$keyTerm}{$itemVar}->value) {\n"; + $output .= "if (\$_from !== null) foreach (\$_from as {$keyTerm}{$itemVar}->value) {\n"; $output .= "{$itemVar}->do_else = false;\n"; if (isset($attributes[ 'key' ]) && isset($itemAttr[ 'key' ])) { $output .= "\$_smarty_tpl->tpl_vars['{$key}']->value = {$itemVar}->key;\n"; @@ -333,9 +333,6 @@ class Smarty_Internal_Compile_Foreachclose extends Smarty_Internal_CompileBase if ($restore === 2) { $output .= "{$itemVar} = {$local}saved;\n"; } - if ($restore > 0) { - $output .= "}\n"; - } $output .= "}\n"; /* @var Smarty_Internal_Compile_Foreach $foreachCompiler */ $foreachCompiler = $compiler->getTagCompiler('foreach');