From b1cd4cd7d29ea3f64c9c39b3f4a842c18dbccb44 Mon Sep 17 00:00:00 2001 From: Uwe Tews Date: Sun, 1 Mar 2015 21:39:54 +0100 Subject: [PATCH] Return to saved output buffer level on exceptions --- libs/sysplugins/smarty_internal_template.php | 5 ++++- libs/sysplugins/smarty_resource_uncompiled.php | 7 +++++-- libs/sysplugins/smarty_template_compiled.php | 7 +++++-- libs/sysplugins/smarty_template_source.php | 7 +++++-- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/libs/sysplugins/smarty_internal_template.php b/libs/sysplugins/smarty_internal_template.php index a510a398..0747aa03 100644 --- a/libs/sysplugins/smarty_internal_template.php +++ b/libs/sysplugins/smarty_internal_template.php @@ -335,6 +335,7 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase */ public function getRenderedTemplateCode() { + $level = ob_get_level(); try { ob_start(); if (empty($this->properties['unifunc']) || !is_callable($this->properties['unifunc'])) { @@ -359,7 +360,9 @@ class Smarty_Internal_Template extends Smarty_Internal_TemplateBase return ob_get_clean(); } catch (Exception $e) { - ob_get_clean(); + while (ob_get_level() > $level) { + ob_end_clean(); + } throw $e; } } diff --git a/libs/sysplugins/smarty_resource_uncompiled.php b/libs/sysplugins/smarty_resource_uncompiled.php index 26a9a57c..a52d86e8 100644 --- a/libs/sysplugins/smarty_resource_uncompiled.php +++ b/libs/sysplugins/smarty_resource_uncompiled.php @@ -56,13 +56,16 @@ abstract class Smarty_Resource_Uncompiled extends Smarty_Resource */ public function render($_template) { + $level = ob_get_level(); + ob_start(); try { - ob_start(); $this->renderUncompiled($_template->source, $_template); return ob_get_clean(); } catch (Exception $e) { - ob_get_clean(); + while (ob_get_level() > $level) { + ob_end_clean(); + } throw $e; } } diff --git a/libs/sysplugins/smarty_template_compiled.php b/libs/sysplugins/smarty_template_compiled.php index 3a3cbd3b..22d9418f 100644 --- a/libs/sysplugins/smarty_template_compiled.php +++ b/libs/sysplugins/smarty_template_compiled.php @@ -149,12 +149,15 @@ class Smarty_Template_Compiled $compileCheck = $_template->smarty->compile_check; $_template->smarty->compile_check = false; if ($_template->source->recompiled) { + $level = ob_get_level(); + ob_start(); try { - ob_start(); eval("?>" . $this->code); } catch (Exception $e) { - ob_get_clean(); + while (ob_get_level() > $level) { + ob_end_clean(); + } throw $e; } ob_get_clean(); diff --git a/libs/sysplugins/smarty_template_source.php b/libs/sysplugins/smarty_template_source.php index 85d31315..dd537f0e 100644 --- a/libs/sysplugins/smarty_template_source.php +++ b/libs/sysplugins/smarty_template_source.php @@ -219,13 +219,16 @@ class Smarty_Template_Source */ public function renderUncompiled(Smarty_Internal_Template $_template) { + $level = ob_get_level(); + ob_start(); try { - ob_start(); $this->handler->renderUncompiled($_template->source, $_template); return ob_get_clean(); } catch (Exception $e) { - ob_get_clean(); + while (ob_get_level() > $level) { + ob_end_clean(); + } throw $e; } }