From 77bec048743243e01f4aac03bd245951df97e13f Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Fri, 10 Dec 2010 07:13:32 +0100 Subject: [PATCH] removed the newline after a comment (closes #195) --- CHANGELOG | 1 + lib/Twig/Lexer.php | 8 ++++++++ test/Twig/Tests/Fixtures/expressions/array.test | 4 ---- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index cfbca2c..e982534 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -8,6 +8,7 @@ Backward incompatibilities: Changes: + * removed the newline after a comment (mimicks PHP behavior) * 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 diff --git a/lib/Twig/Lexer.php b/lib/Twig/Lexer.php index e405be5..d15b690 100644 --- a/lib/Twig/Lexer.php +++ b/lib/Twig/Lexer.php @@ -201,8 +201,16 @@ class Twig_Lexer implements Twig_LexerInterface if (!preg_match('/(.*?)'.preg_quote($this->options['tag_comment'][1], '/').'/As', $this->code, $match, null, $this->cursor)) { throw new Twig_Error_Syntax('unclosed comment', $this->lineno, $this->filename); } + $this->moveCursor($match[0]); $this->moveLineNo($match[0]); + + // mimicks the behavior of PHP by removing the newline that follows instructions if present + if ("\n" === substr($this->code, $this->cursor, 1)) { + $this->moveCursor("\n"); + $this->moveLineNo("\n"); + } + break; case $this->options['tag_block'][0]: diff --git a/test/Twig/Tests/Fixtures/expressions/array.test b/test/Twig/Tests/Fixtures/expressions/array.test index 32f9fe2..24167b6 100644 --- a/test/Twig/Tests/Fixtures/expressions/array.test +++ b/test/Twig/Tests/Fixtures/expressions/array.test @@ -35,15 +35,11 @@ foo,bar 1,bar 0,foo - 1,2 bar - bar - FOO,BAR, - 1,2 -- 1.7.2.5