mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-02 21:46:48 +00:00
Fix capturing output from extensions that still use echo
This commit is contained in:
@@ -43,8 +43,9 @@ class CaptureNode extends Node
|
||||
$compiler
|
||||
->indent()
|
||||
->subcompile($this->getNode('body'))
|
||||
->write("return; yield '';\n")
|
||||
->outdent()
|
||||
->write("})() ?? new \EmptyIterator()")
|
||||
->write('})()')
|
||||
;
|
||||
if ($useYield) {
|
||||
$compiler->raw(', false))');
|
||||
|
||||
@@ -414,7 +414,7 @@ class EnvironmentTest extends TestCase
|
||||
*/
|
||||
public function testLegacyEchoingNode()
|
||||
{
|
||||
$loader = new ArrayLoader(['echo_bar' => 'A{% set v %}B{% test %}C{% endset %}D{% test %}E{{ v }}F']);
|
||||
$loader = new ArrayLoader(['echo_bar' => 'A{% set v %}B{% test %}C{% endset %}D{% test %}E{{ v }}F{% set w %}{% test %}{% endset %}G{{ w }}H']);
|
||||
|
||||
$twig = new Environment($loader);
|
||||
$twig->addExtension(new EnvironmentTest_Extension());
|
||||
@@ -430,7 +430,7 @@ EOF
|
||||
);
|
||||
}
|
||||
|
||||
$this->assertSame('ADbarEBbarCF', $twig->render('echo_bar'));
|
||||
$this->assertSame('ADbarEBbarCFGbarH', $twig->render('echo_bar'));
|
||||
}
|
||||
|
||||
protected function getMockLoader($templateName, $templateContent)
|
||||
|
||||
@@ -60,7 +60,8 @@ public function macro_foo(\$__foo__ = null, \$__bar__ = "Foo", ...\$__varargs__)
|
||||
|
||||
return new Markup(implode('', iterator_to_array((function () use (\$context, \$macros, \$blocks) {
|
||||
yield "foo";
|
||||
})() ?? new \EmptyIterator(), false)), \$this->env->getCharset());
|
||||
return; yield '';
|
||||
})(), false)), \$this->env->getCharset());
|
||||
}
|
||||
EOF
|
||||
, new Environment(new ArrayLoader()),
|
||||
|
||||
@@ -57,7 +57,8 @@ EOF
|
||||
// line 1
|
||||
\$context["foo"] = ('' === \$tmp = implode('', iterator_to_array((function () use (&\$context, \$macros, \$blocks) {
|
||||
yield "foo";
|
||||
})() ?? new \EmptyIterator(), false))) ? '' : new Markup(\$tmp, \$this->env->getCharset());
|
||||
return; yield '';
|
||||
})(), false))) ? '' : new Markup(\$tmp, \$this->env->getCharset());
|
||||
EOF
|
||||
, new Environment(new ArrayLoader()),
|
||||
];
|
||||
@@ -66,7 +67,8 @@ EOF
|
||||
// line 1
|
||||
$context["foo"] = ('' === $tmp = \Twig\Extension\CoreExtension::captureOutput((function () use (&$context, $macros, $blocks) {
|
||||
yield "foo";
|
||||
})() ?? new \EmptyIterator())) ? '' : new Markup($tmp, $this->env->getCharset());
|
||||
return; yield '';
|
||||
})())) ? '' : new Markup($tmp, $this->env->getCharset());
|
||||
EOF
|
||||
, new Environment(new ArrayLoader()),
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user