removed the possibility to use the extends tag from a block (as it is semantically...
authorFabien Potencier <fabien.potencier@gmail.com>
Sat, 6 Aug 2011 07:16:03 +0000 (09:16 +0200)
committerFabien Potencier <fabien.potencier@gmail.com>
Sat, 6 Aug 2011 07:16:10 +0000 (09:16 +0200)
CHANGELOG
lib/Twig/Parser.php
lib/Twig/TokenParser/Extends.php

index 81bb39c..401bd1f 100644 (file)
--- 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)
index 057c1e8..d6310e0 100644 (file)
@@ -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());
index d9fe698..67eacda 100644 (file)
@@ -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());
         }