From 3398b38cf0d0096fe9b0c3c948bf64efee392215 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 3 Apr 2012 19:12:14 +0200 Subject: [PATCH] fixed a regression when a template only extends another one without defining any blocks (closes #683) --- CHANGELOG | 1 + lib/Twig/Node/Module.php | 2 +- .../Tests/Fixtures/tags/inheritance/empty.test | 10 ++++++++++ test/Twig/Tests/Node/ModuleTest.php | 20 ++++++++++++++++++++ test/Twig/Tests/Node/SandboxedModuleTest.php | 20 ++++++++++++++++++++ 5 files changed, 52 insertions(+), 1 deletions(-) create mode 100644 test/Twig/Tests/Fixtures/tags/inheritance/empty.test diff --git a/CHANGELOG b/CHANGELOG index 4d8b7f7..b0e96ec 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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 diff --git a/lib/Twig/Node/Module.php b/lib/Twig/Node/Module.php index c67bc9a..65428f9 100644 --- a/lib/Twig/Node/Module.php +++ b/lib/Twig/Node/Module.php @@ -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); } diff --git a/test/Twig/Tests/Fixtures/tags/inheritance/empty.test b/test/Twig/Tests/Fixtures/tags/inheritance/empty.test new file mode 100644 index 0000000..784f357 --- /dev/null +++ b/test/Twig/Tests/Fixtures/tags/inheritance/empty.test @@ -0,0 +1,10 @@ +--TEST-- +"extends" tag +--TEMPLATE-- +{% extends "foo.twig" %} +--TEMPLATE(foo.twig)-- +{% block content %}FOO{% endblock %} +--DATA-- +return array() +--EXPECT-- +FOO diff --git a/test/Twig/Tests/Node/ModuleTest.php b/test/Twig/Tests/Node/ModuleTest.php index 4b2b2e9..f60f105 100644 --- a/test/Twig/Tests/Node/ModuleTest.php +++ b/test/Twig/Tests/Node/ModuleTest.php @@ -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"; diff --git a/test/Twig/Tests/Node/SandboxedModuleTest.php b/test/Twig/Tests/Node/SandboxedModuleTest.php index f86442b..db1bd89 100644 --- a/test/Twig/Tests/Node/SandboxedModuleTest.php +++ b/test/Twig/Tests/Node/SandboxedModuleTest.php @@ -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"; -- 1.7.2.5