From e1fb2ad6887af10d8f673c7955241e182f808262 Mon Sep 17 00:00:00 2001 From: Simon Wisselink Date: Thu, 22 Sep 2022 14:56:33 +0200 Subject: [PATCH] clean output buffer for Throwable instead of just Exception (#798) * clean output buffer for Throwable instead of just Exception --- CHANGELOG.md | 3 +++ libs/sysplugins/smarty_internal_templatebase.php | 10 +++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bb998347..a82ed892 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed +- Output buffer is now cleaned for internal PHP errors as well, not just for Exceptions [#514](https://github.com/smarty-php/smarty/issues/514) + ## [3.1.47] - 2022-09-14 ### Security diff --git a/libs/sysplugins/smarty_internal_templatebase.php b/libs/sysplugins/smarty_internal_templatebase.php index 200c11bb..741a9eea 100644 --- a/libs/sysplugins/smarty_internal_templatebase.php +++ b/libs/sysplugins/smarty_internal_templatebase.php @@ -246,7 +246,15 @@ abstract class Smarty_Internal_TemplateBase extends Smarty_Internal_Data error_reporting($_smarty_old_error_level); } return $result; - } catch (Exception $e) { + } catch (Exception $e) { // PHP 5.x specific + while (ob_get_level() > $level) { + ob_end_clean(); + } + if (isset($_smarty_old_error_level)) { + error_reporting($_smarty_old_error_level); + } + throw $e; + } catch (Throwable $e) { // For PHP ^7.0 this can also catch Errors while (ob_get_level() > $level) { ob_end_clean(); }