From c1c725171e2547e4bae75425ebe98db54b656060 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 28 Apr 2010 19:51:05 +0200 Subject: [PATCH] added an exception when trying to nest block definitions (closes #45) --- lib/Twig/TokenParser/Block.php | 7 +++++++ 1 files changed, 7 insertions(+), 0 deletions(-) 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)) -- 1.7.2.5