From 801f3e638c76d57172b07d685c18f47eb1efbb27 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sat, 6 Aug 2011 09:16:03 +0200 Subject: [PATCH] removed the possibility to use the extends tag from a block (as it is semantically incorrect and it probably does not work as you expect it to in this case) --- CHANGELOG | 1 + lib/Twig/Parser.php | 5 +++++ lib/Twig/TokenParser/Extends.php | 4 ++++ 3 files changed, 10 insertions(+), 0 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 81bb39c..401bd1f 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,6 @@ * 1.2.0 + * removed the possibility to use the "extends" tag from a block * added "if" modifier support to "for" loops * 1.1.2 (2011-07-30) diff --git a/lib/Twig/Parser.php b/lib/Twig/Parser.php index 057c1e8..d6310e0 100644 --- a/lib/Twig/Parser.php +++ b/lib/Twig/Parser.php @@ -244,6 +244,11 @@ class Twig_Parser implements Twig_ParserInterface } } + public function isMainScope() + { + return 1 === count($this->importedFunctions); + } + public function pushLocalScope() { array_unshift($this->importedFunctions, array()); diff --git a/lib/Twig/TokenParser/Extends.php b/lib/Twig/TokenParser/Extends.php index d9fe698..67eacda 100644 --- a/lib/Twig/TokenParser/Extends.php +++ b/lib/Twig/TokenParser/Extends.php @@ -28,6 +28,10 @@ class Twig_TokenParser_Extends extends Twig_TokenParser */ public function parse(Twig_Token $token) { + if (!$this->parser->isMainScope()) { + throw new Twig_Error_Syntax('Cannot extend from a block', $token->getLine()); + } + if (null !== $this->parser->getParent()) { throw new Twig_Error_Syntax('Multiple extends tags are forbidden', $token->getLine()); } -- 1.7.2.5