From b327a48a29bd47c83ce9d10181e217553a9e863d Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Tue, 24 Jan 2012 17:39:13 +0100 Subject: [PATCH] Protect the Parser against recursive parsing issues --- lib/Twig/Parser.php | 13 ++++++++++++- 1 files changed, 12 insertions(+), 1 deletions(-) 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) -- 1.7.2.5