Skip to content

Commit

Permalink
Sandbox foreachVars in templates
Browse files Browse the repository at this point in the history
Nesting the same template inside a `foreach` loop that is also accessed inside the nested call will overwrite the values from the outer template due to identical identifiers being used.

The sandbox did not protected `$this->foreachVars` despite being stateful.

See #4431
Fixes #4444
  • Loading branch information
dtdesign committed Aug 8, 2021
1 parent f23c576 commit 939a258
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,10 @@ public function getPluginClassName($type, $tag)
public function enableSandbox()
{
$index = \count($this->sandboxVars);
$this->sandboxVars[$index] = $this->v;
$this->sandboxVars[$index] = [
'foreachVars' => $this->foreachVars,
'v' => $this->v,
];
}

/**
Expand All @@ -555,7 +558,9 @@ public function disableSandbox()
throw new SystemException('TemplateEngine is currently not running in a sandbox.');
}

$this->v = \array_pop($this->sandboxVars);
$values = \array_pop($this->sandboxVars);
$this->foreachVars = $values['foreachVars'];
$this->v = $values['v'];
}

/**
Expand Down

0 comments on commit 939a258

Please sign in to comment.