From ae250f6b6f354f091dc0a5f7621eef275d87a41b Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Thu, 8 Dec 2011 09:29:20 +0100 Subject: [PATCH] fixed the lexer when an operator ending with a letter ends a line --- CHANGELOG | 1 + lib/Twig/Lexer.php | 2 +- test/Twig/Tests/LexerTest.php | 11 +++++++++++ 3 files changed, 13 insertions(+), 1 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 60839c2..76b62a1 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,6 @@ * 1.5.0 + * fixed the lexer when an operator ending with a letter ends a line * added string interpolation support * enhanced exceptions for unknown filters, functions, tests, and tags diff --git a/lib/Twig/Lexer.php b/lib/Twig/Lexer.php index 9df8799..9810ab2 100644 --- a/lib/Twig/Lexer.php +++ b/lib/Twig/Lexer.php @@ -372,7 +372,7 @@ class Twig_Lexer implements Twig_LexerInterface // an operator that ends with a character must be followed by // a whitespace or a parenthesis if (ctype_alpha($operator[$length - 1])) { - $regex[] = preg_quote($operator, '/').'(?=[ ()])'; + $regex[] = preg_quote($operator, '/').'(?=[\s()])'; } else { $regex[] = preg_quote($operator, '/'); } diff --git a/test/Twig/Tests/LexerTest.php b/test/Twig/Tests/LexerTest.php index 729869f..ce87898 100644 --- a/test/Twig/Tests/LexerTest.php +++ b/test/Twig/Tests/LexerTest.php @@ -235,4 +235,15 @@ class Twig_Tests_LexerTest extends PHPUnit_Framework_TestCase $stream->expect(Twig_Token::INTERPOLATION_END_TYPE); $stream->expect(Twig_Token::BLOCK_END_TYPE); } + + public function testOperatorEndingWithALetterAtTheEndOfALine() + { + $template = "{{ 1 and\n0}}"; + + $lexer = new Twig_Lexer(new Twig_Environment()); + $stream = $lexer->tokenize($template); + $stream->expect(Twig_Token::VAR_START_TYPE); + $stream->expect(Twig_Token::NUMBER_TYPE, 1); + $stream->expect(Twig_Token::OPERATOR_TYPE, 'and'); + } } -- 1.7.2.5