Protect the Parser against recursive parsing issues
authorJordi Boggiano <j.boggiano@seld.be>
Tue, 24 Jan 2012 16:39:13 +0000 (17:39 +0100)
committerJordi Boggiano <j.boggiano@seld.be>
Tue, 24 Jan 2012 16:39:13 +0000 (17:39 +0100)
lib/Twig/Parser.php

index b626d77..15325da 100644 (file)
@@ -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)