* 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
protected $env;
protected $reservedMacroNames;
protected $importedFunctions;
- protected $tmpVarCount;
protected $traits;
protected $embeddedTemplates = array();
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));
}
/**
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();
$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(<<<EOF
+{% from _self import foo %}
+
+{% macro foo() %}
+ {{ foo }}
+{% endmacro %}
+EOF
+ ));
+ }
+
protected function getParserForFilterBodyNodes()
{
$parser = new TestParser(new Twig_Environment());