From: Fabien Potencier Date: Wed, 28 Apr 2010 17:51:05 +0000 (+0200) Subject: added an exception when trying to nest block definitions (closes #45) X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=c1c725171e2547e4bae75425ebe98db54b656060;p=web%2Fkonrad%2Ftwig.git added an exception when trying to nest block definitions (closes #45) --- diff --git a/lib/Twig/TokenParser/Block.php b/lib/Twig/TokenParser/Block.php index 077347f..0d35aba 100644 --- a/lib/Twig/TokenParser/Block.php +++ b/lib/Twig/TokenParser/Block.php @@ -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))