From d50cdca841470a16b0a78f3c57c2828c368b2e83 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Thu, 18 Feb 2021 15:54:18 +0100 Subject: [PATCH] {capture} creates Html object only in HTML-TEXT context --- src/Latte/Macros/CoreMacros.php | 2 +- tests/Latte/CoreMacros.capture.phpt | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Latte/Macros/CoreMacros.php b/src/Latte/Macros/CoreMacros.php index 083e32e72..7409bf92a 100644 --- a/src/Latte/Macros/CoreMacros.php +++ b/src/Latte/Macros/CoreMacros.php @@ -407,7 +407,7 @@ public function macroCapture(MacroNode $node, PhpWriter $writer): string */ public function macroCaptureEnd(MacroNode $node, PhpWriter $writer): string { - $body = in_array($node->context[0], [Engine::CONTENT_HTML, Engine::CONTENT_XHTML], true) + $body = in_array(implode($node->context), [Engine::CONTENT_HTML, Engine::CONTENT_XHTML], true) ? 'ob_get_length() ? new LR\\Html(ob_get_clean()) : ob_get_clean()' : 'ob_get_clean()'; return $writer->write( diff --git a/tests/Latte/CoreMacros.capture.phpt b/tests/Latte/CoreMacros.capture.phpt index 2f0d8a0a2..6361c33f9 100644 --- a/tests/Latte/CoreMacros.capture.phpt +++ b/tests/Latte/CoreMacros.capture.phpt @@ -45,3 +45,8 @@ Assert::match( // bug #215 '', $latte->renderToString('{capture $var|strip} {/capture}') ); + +Assert::match( + ' <foo>', + $latte->renderToString(' {$x}') +);