From 08bd27f7720c262069d278cf84994839a7769af8 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Thu, 2 Dec 2010 16:13:54 +0100 Subject: [PATCH] added a syntax error exception when parent block is used on a template that does not extend another one --- CHANGELOG | 1 + lib/Twig/TokenParser/Parent.php | 4 ++++ 2 files changed, 5 insertions(+), 0 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index f493b4b..8ce0ffd 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,6 @@ * 0.9.10 + * added a syntax error exception when parent block is used on a template that does not extend another one * made the Escaper and Optimizer extensions enabled by default * fixed sandbox extension when used with auto output escaping * fixed escaper when wrapping a Twig_Node_Print (the original class must be preserved) diff --git a/lib/Twig/TokenParser/Parent.php b/lib/Twig/TokenParser/Parent.php index d9204e6..afde369 100644 --- a/lib/Twig/TokenParser/Parent.php +++ b/lib/Twig/TokenParser/Parent.php @@ -25,6 +25,10 @@ class Twig_TokenParser_Parent extends Twig_TokenParser } $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE); + if (!$this->parser->getParent()) { + throw new Twig_Error_Syntax('Calling "parent" on a template that does not extend another one is forbidden', $token->getLine()); + } + return new Twig_Node_Parent($this->parser->peekBlockStack(), $token->getLine(), $this->getTag()); } -- 1.7.2.5