From 615804bf74f58271d94c4943d56ae27fa8c2786b Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Thu, 8 Nov 2012 08:56:03 +0100 Subject: [PATCH] fixed regression when calling a macro inside another one (closes #889) --- CHANGELOG | 1 + lib/Twig/Node/Macro.php | 2 +- test/Twig/Tests/Fixtures/macros/nested_calls.test | 18 ++++++++++++++++++ test/Twig/Tests/Node/MacroTest.php | 2 +- 4 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 test/Twig/Tests/Fixtures/macros/nested_calls.test diff --git a/CHANGELOG b/CHANGELOG index b91e14b..5c8a3d8 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,6 @@ * 1.11.1 (2012-XX-XX) + * fixed escaping when calling a macro inside another one (regression introduced in 1.9.1) * optimized variable access on PHP 5.4 * fixed a crash of the C extension when an exception was thrown from a macro called without being imported (using _self.XXX) diff --git a/lib/Twig/Node/Macro.php b/lib/Twig/Node/Macro.php index bdbef27..8bb5d9d 100644 --- a/lib/Twig/Node/Macro.php +++ b/lib/Twig/Node/Macro.php @@ -76,7 +76,7 @@ class Twig_Node_Macro extends Twig_Node ->write("throw \$e;\n") ->outdent() ->write("}\n\n") - ->write("return ob_get_clean();\n") + ->write("return ('' === \$tmp = ob_get_clean()) ? '' : new Twig_Markup(\$tmp, \$this->env->getCharset());\n") ->outdent() ->write("}\n\n") ; diff --git a/test/Twig/Tests/Fixtures/macros/nested_calls.test b/test/Twig/Tests/Fixtures/macros/nested_calls.test new file mode 100644 index 0000000..cd25428 --- /dev/null +++ b/test/Twig/Tests/Fixtures/macros/nested_calls.test @@ -0,0 +1,18 @@ +--TEST-- +macro +--TEMPLATE-- +{% import _self as macros %} + +{% macro foo(data) %} + {{ data }} +{% endmacro %} + +{% macro bar() %} +
+{% endmacro %} + +{{ macros.foo(macros.bar()) }} +--DATA-- +return array(); +--EXPECT-- +
diff --git a/test/Twig/Tests/Node/MacroTest.php b/test/Twig/Tests/Node/MacroTest.php index b6841d3..39e8131 100644 --- a/test/Twig/Tests/Node/MacroTest.php +++ b/test/Twig/Tests/Node/MacroTest.php @@ -60,7 +60,7 @@ public function getfoo(\$_foo = null) throw \$e; } - return ob_get_clean(); + return ('' === \$tmp = ob_get_clean()) ? '' : new Twig_Markup(\$tmp, \$this->env->getCharset()); } EOF ), -- 1.7.2.5