From: Fabien Potencier Date: Tue, 10 Jul 2012 16:30:12 +0000 (+0200) Subject: made the parsing independent of the template loaders X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=611f4451e3e44b582fc49e901fdf0f149ee50498;p=web%2Fkonrad%2Ftwig.git made the parsing independent of the template loaders This basically reverts 57ff88255ef35ad8da325d0cb0bf140e653b132c --- diff --git a/CHANGELOG b/CHANGELOG index 0b9d53d..8a322bd 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,6 @@ * 1.9.0 (2012-XX-XX) + * made the parsing independent of the template loaders * fixed exception trace when an error occurs when rendering a child template * added escaping strategies for CSS, URL, and HTML attributes * fixed nested embed tag calls diff --git a/lib/Twig/Parser.php b/lib/Twig/Parser.php index 771a7bd..66f5d2a 100644 --- a/lib/Twig/Parser.php +++ b/lib/Twig/Parser.php @@ -30,7 +30,6 @@ class Twig_Parser implements Twig_ParserInterface protected $env; protected $reservedMacroNames; protected $importedFunctions; - protected $tmpVarCount; protected $traits; protected $embeddedTemplates = array(); @@ -51,7 +50,7 @@ class Twig_Parser implements Twig_ParserInterface public function getVarName() { - return sprintf('__internal_%s_%d', substr($this->env->getTemplateClass($this->stream->getFilename()), strlen($this->env->getTemplateClassPrefix())), ++$this->tmpVarCount); + return sprintf('__internal_%s', hash('sha1', uniqid(mt_rand(), true), false)); } /** @@ -68,8 +67,6 @@ class Twig_Parser implements Twig_ParserInterface unset($vars['stack'], $vars['env'], $vars['handlers'], $vars['visitors'], $vars['expressionParser']); $this->stack[] = $vars; - $this->tmpVarCount = 0; - // tag handlers if (null === $this->handlers) { $this->handlers = $this->env->getTokenParsers(); diff --git a/test/Twig/Tests/ParserTest.php b/test/Twig/Tests/ParserTest.php index 76f257a..1e773a6 100644 --- a/test/Twig/Tests/ParserTest.php +++ b/test/Twig/Tests/ParserTest.php @@ -115,6 +115,26 @@ class Twig_Tests_ParserTest extends PHPUnit_Framework_TestCase $this->assertEquals(null, $parser->getParent()); } + // The getVarName() must not depend on the template loaders, + // If this test does not throw any exception, that's good. + // see https://github.com/symfony/symfony/issues/4218 + public function testGetVarName() + { + $twig = new Twig_Environment(null, array( + 'autoescape' => false, + 'optimizations' => 0, + )); + + $twig->parse($twig->tokenize(<<