From: Fabien Potencier Date: Mon, 25 Jul 2011 16:12:16 +0000 (+0200) Subject: fixed output when a macro throws an exception X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=ea839728697670fdb476a54f5a24bca8702ef445;p=web%2Fkonrad%2Ftwig.git fixed output when a macro throws an exception --- 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(); }