From ea839728697670fdb476a54f5a24bca8702ef445 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 25 Jul 2011 18:12:16 +0200 Subject: [PATCH] fixed output when a macro throws an exception --- CHANGELOG | 1 + lib/Twig/Node/Macro.php | 10 +++++++++- test/Twig/Tests/Node/MacroTest.php | 8 +++++++- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 2e6bd7c..c06e02d 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,6 +2,7 @@ Changes: + * fixed output when a macro throws an exception * fixed a parsing problem when a large chunk of text is enclosed in a comment tag * 1.1.1 (2011-07-17) diff --git a/lib/Twig/Node/Macro.php b/lib/Twig/Node/Macro.php index d77bc47..9f95570 100644 --- a/lib/Twig/Node/Macro.php +++ b/lib/Twig/Node/Macro.php @@ -55,8 +55,16 @@ class Twig_Node_Macro extends Twig_Node ->outdent() ->write("));\n\n") ->write("ob_start();\n") + ->write("try {\n") + ->indent() ->subcompile($this->getNode('body')) - ->raw("\n") + ->outdent() + ->write("} catch(Exception \$e) {\n") + ->indent() + ->write("ob_end_clean();\n\n") + ->write("throw \$e;\n") + ->outdent() + ->write("}\n\n") ->write("return ob_get_clean();\n") ->outdent() ->write("}\n\n") diff --git a/test/Twig/Tests/Node/MacroTest.php b/test/Twig/Tests/Node/MacroTest.php index 904cfb4..66d5fec 100644 --- a/test/Twig/Tests/Node/MacroTest.php +++ b/test/Twig/Tests/Node/MacroTest.php @@ -51,7 +51,13 @@ public function getfoo(\$foo = null) )); ob_start(); - echo "foo"; + try { + echo "foo"; + } catch(Exception \$e) { + ob_end_clean(); + + throw \$e; + } return ob_get_clean(); } -- 1.7.2.5