fixed a regression when a template only extends another one without defining any blocks (closes #683)

This commit is contained in:
Fabien Potencier
2012-04-03 19:12:14 +02:00
parent e2220bb282
commit 3398b38cf0
5 changed files with 52 additions and 1 deletions
+1
View File
@@ -1,5 +1,6 @@
* 1.7.0 (2012-XX-XX)
* fixed a regression when a template only extends another one without defining any blocks
* added compilation checks to avoid misuses of the sandbox tag
* fixed filesystem loader freshness logic for high traffic websites
+1 -1
View File
@@ -37,7 +37,7 @@ class Twig_Node_Module extends Twig_Node
{
$this->compileClassHeader($compiler);
if (count($this->getNode('blocks')) || count($this->getNode('traits'))) {
if (count($this->getNode('blocks')) || count($this->getNode('traits')) || null === $this->getNode('parent') || $this->getNode('parent') instanceof Twig_Node_Expression_Constant) {
$this->compileConstructor($compiler);
}
@@ -0,0 +1,10 @@
--TEST--
"extends" tag
--TEMPLATE--
{% extends "foo.twig" %}
--TEMPLATE(foo.twig)--
{% block content %}FOO{% endblock %}
--DATA--
return array()
--EXPECT--
FOO
+20
View File
@@ -69,6 +69,16 @@ class Twig_Tests_Node_ModuleTest extends Twig_Tests_Node_TestCase
/* foo.twig */
class __TwigTemplate_be925a7b06dda0dfdbd18a1509f7eb34 extends Twig_Template
{
public function __construct(Twig_Environment \$env)
{
parent::__construct(\$env);
\$this->parent = false;
\$this->blocks = array(
);
}
protected function doDisplay(array \$context, array \$blocks = array())
{
echo "foo";
@@ -99,6 +109,16 @@ EOF
/* foo.twig */
class __TwigTemplate_be925a7b06dda0dfdbd18a1509f7eb34 extends Twig_Template
{
public function __construct(Twig_Environment \$env)
{
parent::__construct(\$env);
\$this->parent = \$this->env->loadTemplate("layout.twig");
\$this->blocks = array(
);
}
protected function doGetParent(array \$context)
{
return "layout.twig";
@@ -67,6 +67,16 @@ class Twig_Tests_Node_SandboxedModuleTest extends Twig_Tests_Node_TestCase
/* foo.twig */
class __TwigTemplate_be925a7b06dda0dfdbd18a1509f7eb34 extends Twig_Template
{
public function __construct(Twig_Environment \$env)
{
parent::__construct(\$env);
\$this->parent = false;
\$this->blocks = array(
);
}
protected function doDisplay(array \$context, array \$blocks = array())
{
\$this->checkSecurity();
@@ -110,6 +120,16 @@ EOF
/* foo.twig */
class __TwigTemplate_be925a7b06dda0dfdbd18a1509f7eb34 extends Twig_Template
{
public function __construct(Twig_Environment \$env)
{
parent::__construct(\$env);
\$this->parent = \$this->env->loadTemplate("layout.twig");
\$this->blocks = array(
);
}
protected function doGetParent(array \$context)
{
return "layout.twig";