From 93425b32cb2a1dd513ae8e31e2f808b934056c2a Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 9 May 2011 17:35:00 +0200 Subject: [PATCH] fixed parsing problem when a large chunk of text is enclosed in a raw tag This is a quick and ugly fix... This should be refactored later on --- lib/Twig/Lexer.php | 10 ++++++++-- 1 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/Twig/Lexer.php b/lib/Twig/Lexer.php index a27a111..184f8a8 100644 --- a/lib/Twig/Lexer.php +++ b/lib/Twig/Lexer.php @@ -158,9 +158,15 @@ class Twig_Lexer implements Twig_LexerInterface case $this->options['tag_block'][0]: // raw data? - if (preg_match('/\s*raw\s*'.preg_quote($this->options['tag_block'][1], '/').'(.*?)'.preg_quote($this->options['tag_block'][0], '/').'\s*endraw\s*'.preg_quote($this->options['tag_block'][1], '/').'/As', $this->code, $match, null, $this->cursor)) { - $this->pushToken(Twig_Token::TEXT_TYPE, $match[1]); + if (preg_match('/\s*raw\s*'.preg_quote($this->options['tag_block'][1], '/').'/As', $this->code, $match, null, $this->cursor)) { $this->moveCursor($match[0]); + if (!preg_match('/'.preg_quote($this->options['tag_block'][0], '/').'\s*endraw\s*'.preg_quote($this->options['tag_block'][1], '/').'/s', $this->code, $match, null, $this->cursor)) { + throw new Twig_Error_Syntax(sprintf('Unexpected end of file: Unclosed "block"')); + } + $pos = strpos($this->code, $match[0], $this->cursor); + $text = substr($this->code, $this->cursor, $pos - $this->cursor); + $this->pushToken(Twig_Token::TEXT_TYPE, $text); + $this->moveCursor($text.$match[0]); $this->state = self::STATE_DATA; } else { $this->pushToken(Twig_Token::BLOCK_START_TYPE); -- 1.7.2.5