From: Fabien Potencier Date: Thu, 1 Sep 2011 06:08:16 +0000 (+0200) Subject: fixed algorithm that determines if a template using inheritance is valid (no output... X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=f20450d13d816c49317f9e5447f7b7c219f8279b;p=web%2Fkonrad%2Ftwig.git fixed algorithm that determines if a template using inheritance is valid (no output between block definitions) --- diff --git a/CHANGELOG b/CHANGELOG index 829d765..eda9d28 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,6 @@ * 1.2.0 + * fixed algorithm that determines if a template using inheritance is valid (no output between block definitions) * added better support for encoding problems when escaping a string (available as of PHP 5.4) * added a way to ignore a missing template when using the "include" tag ({% include "foo" ignore missing %}) * added support for an array of templates to the "include" and "extends" tags ({% include ['foo', 'bar'] %}) diff --git a/lib/Twig/Parser.php b/lib/Twig/Parser.php index 9ff315a..0a4ae3e 100644 --- a/lib/Twig/Parser.php +++ b/lib/Twig/Parser.php @@ -310,8 +310,13 @@ class Twig_Parser implements Twig_ParserInterface throw new Twig_Error_Syntax('A template that extends another one cannot have a body.', $node->getLine(), $this->stream->getFilename()); } + // bypass "set" nodes as they "capture" the output + if ($node instanceof Twig_Node_Set) { + return $node; + } + if ($node instanceof Twig_NodeOutputInterface) { - return null; + return; } foreach ($node as $k => $n) { diff --git a/test/Twig/Tests/ParserTest.php b/test/Twig/Tests/ParserTest.php index 614a867..577311d 100644 --- a/test/Twig/Tests/ParserTest.php +++ b/test/Twig/Tests/ParserTest.php @@ -40,6 +40,10 @@ class Twig_Tests_ParserTest extends PHPUnit_Framework_TestCase $input = new Twig_Node(array(new Twig_Node_Set(false, new Twig_Node(), new Twig_Node(), 0))), $input, ), + array( + $input = new Twig_Node(array(new Twig_Node_Set(true, new Twig_Node(), new Twig_Node(array(new Twig_Node(array(new Twig_Node_Text('foo', 0))))), 0))), + $input, + ), ); }