mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-12 02:16:41 +00:00
fix: #4029 when use_yield is true CaptureNode use iterator_to_array preserveKeys argument to false
This commit is contained in:
@@ -44,9 +44,11 @@ class CaptureNode extends Node
|
||||
->indent()
|
||||
->subcompile($this->getNode('body'))
|
||||
->outdent()
|
||||
->write("})() ?? new \EmptyIterator())")
|
||||
->write("})() ?? new \EmptyIterator()")
|
||||
;
|
||||
if ($useYield) {
|
||||
$compiler->raw(', false))');
|
||||
} else {
|
||||
$compiler->raw(')');
|
||||
}
|
||||
if (!$this->getAttribute('raw')) {
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
--TEST--
|
||||
#4029 When use_yield is true, CaptureNode fall in iterator_to_array pitfall regarding index overwrite
|
||||
--TEMPLATE--
|
||||
{%- set tmp -%}
|
||||
{%- block foo 'foo' -%}
|
||||
{%- block bar 'bar' -%}
|
||||
{%- endset -%}
|
||||
{{ tmp }}
|
||||
--DATA--
|
||||
return []
|
||||
--CONFIG--
|
||||
return ['use_yield' => true]
|
||||
--EXPECT--
|
||||
foobar
|
||||
@@ -60,7 +60,7 @@ 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())), \$this->env->getCharset());
|
||||
})() ?? new \EmptyIterator(), false)), \$this->env->getCharset());
|
||||
}
|
||||
EOF
|
||||
, new Environment(new ArrayLoader()),
|
||||
|
||||
@@ -57,7 +57,7 @@ EOF
|
||||
// line 1
|
||||
\$context["foo"] = ('' === \$tmp = implode('', iterator_to_array((function () use (&\$context, \$macros, \$blocks) {
|
||||
yield "foo";
|
||||
})() ?? new \EmptyIterator()))) ? '' : new Markup(\$tmp, \$this->env->getCharset());
|
||||
})() ?? new \EmptyIterator(), false))) ? '' : new Markup(\$tmp, \$this->env->getCharset());
|
||||
EOF
|
||||
, new Environment(new ArrayLoader()),
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user