mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-19 05:46:41 +00:00
made the parsing independent of the template loaders
This basically reverts 57ff88255e
This commit is contained in:
@@ -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
|
||||
|
||||
+1
-4
@@ -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();
|
||||
|
||||
@@ -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(<<<EOF
|
||||
{% from _self import foo %}
|
||||
|
||||
{% macro foo() %}
|
||||
{{ foo }}
|
||||
{% endmacro %}
|
||||
EOF
|
||||
));
|
||||
}
|
||||
|
||||
protected function getParserForFilterBodyNodes()
|
||||
{
|
||||
$parser = new TestParser(new Twig_Environment());
|
||||
|
||||
Reference in New Issue
Block a user