mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-15 11:56:50 +00:00
Prevent infinite loops
This commit is contained in:
@@ -105,6 +105,10 @@ final class LoopContext
|
|||||||
|
|
||||||
public function __invoke($iterator): \Generator
|
public function __invoke($iterator): \Generator
|
||||||
{
|
{
|
||||||
|
if ($this->depth > 50) {
|
||||||
|
throw new \RuntimeException('Nesting level too deep.');
|
||||||
|
}
|
||||||
|
|
||||||
yield from ($this->recurseFunc)(new LoopIterator($iterator), $this->parent, $this->blocks, $this->recurseFunc, $this->depth + 1);
|
yield from ($this->recurseFunc)(new LoopIterator($iterator), $this->parent, $this->blocks, $this->recurseFunc, $this->depth + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
--TEST--
|
||||||
|
"for" tags prevents infinite recursions
|
||||||
|
--TEMPLATE--
|
||||||
|
{% for item in sitemap %}
|
||||||
|
{{ loop(sitemap) }}
|
||||||
|
{% endfor %}
|
||||||
|
--DATA--
|
||||||
|
return [
|
||||||
|
'sitemap' => [
|
||||||
|
[ 'title' => 'foo' ],
|
||||||
|
[ 'title' => 'bar' ],
|
||||||
|
],
|
||||||
|
]
|
||||||
|
--EXCEPTION--
|
||||||
|
Twig\Error\RuntimeError: An exception has been thrown during the rendering of a template ("Nesting level too deep.") in "index.twig" at line 3.
|
||||||
Reference in New Issue
Block a user