From: Jordi Boggiano Date: Tue, 24 Jan 2012 16:39:13 +0000 (+0100) Subject: Protect the Parser against recursive parsing issues X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=b327a48a29bd47c83ce9d10181e217553a9e863d;p=web%2Fkonrad%2Ftwig.git Protect the Parser against recursive parsing issues --- diff --git a/lib/Twig/Parser.php b/lib/Twig/Parser.php index b626d77..15325da 100644 --- a/lib/Twig/Parser.php +++ b/lib/Twig/Parser.php @@ -18,6 +18,7 @@ */ class Twig_Parser implements Twig_ParserInterface { + protected $stack = array(); protected $stream; protected $parent; protected $handlers; @@ -61,6 +62,10 @@ class Twig_Parser implements Twig_ParserInterface */ public function parse(Twig_TokenStream $stream) { + $vars = get_object_vars($this); + unset($vars['stack'], $vars['env']); + $this->stack[] = $vars; + $this->tmpVarCount = 0; // tag handlers @@ -102,7 +107,13 @@ class Twig_Parser implements Twig_ParserInterface $traverser = new Twig_NodeTraverser($this->env, $this->visitors); - return $traverser->traverse($node); + $node = $traverser->traverse($node); + + foreach (array_pop($this->stack) as $key => $val) { + $this->$key = $val; + } + + return $node; } public function subparse($test, $dropNeedle = false)