From 53d01ffed705541148b898891575bbe34d632bfb Mon Sep 17 00:00:00 2001 From: Tobias Schultze Date: Thu, 24 Sep 2015 16:26:19 +0200 Subject: [PATCH] use try-finally for macro compilation --- lib/Twig/Node/Macro.php | 10 +++++----- test/Twig/Tests/Node/MacroTest.php | 8 +++----- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/lib/Twig/Node/Macro.php b/lib/Twig/Node/Macro.php index 10152c9f32..bbab2058a0 100644 --- a/lib/Twig/Node/Macro.php +++ b/lib/Twig/Node/Macro.php @@ -108,14 +108,14 @@ public function compile(Twig_Compiler $compiler) ->write("try {\n") ->indent() ->subcompile($this->getNode('body')) + ->raw("\n") + ->write("return ('' === \$tmp = ob_get_contents()) ? '' : new Twig_Markup(\$tmp, \$this->env->getCharset());\n") ->outdent() - ->write("} catch (Exception \$e) {\n") + ->write("} finally {\n") ->indent() - ->write("ob_end_clean();\n\n") - ->write("throw \$e;\n") + ->write("ob_end_clean();\n") ->outdent() - ->write("}\n\n") - ->write("return ('' === \$tmp = ob_get_clean()) ? '' : new Twig_Markup(\$tmp, \$this->env->getCharset());\n") + ->write("}\n") ->outdent() ->write("}\n\n") ; diff --git a/test/Twig/Tests/Node/MacroTest.php b/test/Twig/Tests/Node/MacroTest.php index ec279779fc..7c4d0a84d5 100644 --- a/test/Twig/Tests/Node/MacroTest.php +++ b/test/Twig/Tests/Node/MacroTest.php @@ -55,13 +55,11 @@ public function macro_foo(\$__foo__ = null, \$__bar__ = "Foo"$declaration) ob_start(); try { echo "foo"; - } catch (Exception \$e) { - ob_end_clean(); - throw \$e; + return ('' === \$tmp = ob_get_contents()) ? '' : new Twig_Markup(\$tmp, \$this->env->getCharset()); + } finally { + ob_end_clean(); } - - return ('' === \$tmp = ob_get_clean()) ? '' : new Twig_Markup(\$tmp, \$this->env->getCharset()); } EOF ),