added an exception when trying to nest block definitions (closes #45)
authorFabien Potencier <fabien.potencier@gmail.com>
Wed, 28 Apr 2010 17:51:05 +0000 (19:51 +0200)
committerFabien Potencier <fabien.potencier@gmail.com>
Wed, 28 Apr 2010 17:51:08 +0000 (19:51 +0200)
lib/Twig/TokenParser/Block.php

index 077347f..0d35aba 100644 (file)
@@ -14,12 +14,19 @@ class Twig_TokenParser_Block extends Twig_TokenParser
   public function parse(Twig_Token $token)
   {
     $lineno = $token->getLine();
+
     $stream = $this->parser->getStream();
     $name = $stream->expect(Twig_Token::NAME_TYPE)->getValue();
     if ($this->parser->hasBlock($name))
     {
       throw new Twig_SyntaxError("The block '$name' has already been defined", $lineno);
     }
+
+    if (null !== $current = $this->parser->getCurrentBlock())
+    {
+      throw new Twig_SyntaxError("Blocks cannot be nested (you are trying to define a '$name' block inside the '$current' block)", $lineno);
+    }
+
     $this->parser->setCurrentBlock($name);
 
     if ($stream->test(Twig_Token::BLOCK_END_TYPE))