Skip to content

Commit

Permalink
bug #3046 Fixed: Endless loop if more than one parent without the mac…
Browse files Browse the repository at this point in the history
…ro exists (nea)

This PR was squashed before being merged into the 2.x branch (closes #3046).

Discussion
----------

Fixed: Endless loop if more than one parent without the macro exists

Hi @fabpot

I made a quick fix for the parent macro method call fix you did for me in #3042. Your code works in case the direct parent has the macro. But if there is a longer hierarchy and the looked for macro is in a parent template +1 it runs into an endless loop because the `->getParent()` method is always called on `$template` but never the newer `$parent`.

Best

Commits
-------

4497083 Fixed: Endless loop if more than one parent without the macro exists
  • Loading branch information
fabpot committed Jun 3, 2019
2 parents 0840c79 + 4497083 commit 25cc3e4
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Extension/CoreExtension.php
Expand Up @@ -1083,7 +1083,8 @@ function twig_capitalize_string_filter(Environment $env, $string)
function twig_call_macro(Template $template, string $method, array $args, int $lineno, array $context, Source $source)
{
if (!method_exists($template, $method)) {
while ($parent = $template->getParent($context)) {
$parent = $template;
while ($parent = $parent->getParent($context)) {
if (method_exists($parent, $method)) {
return $parent->$method(...$args);
}
Expand Down

0 comments on commit 25cc3e4

Please sign in to comment.