removed the newline after a comment (closes #195)
authorFabien Potencier <fabien.potencier@gmail.com>
Fri, 10 Dec 2010 06:13:32 +0000 (07:13 +0100)
committerFabien Potencier <fabien.potencier@gmail.com>
Fri, 10 Dec 2010 06:13:32 +0000 (07:13 +0100)
CHANGELOG
lib/Twig/Lexer.php
test/Twig/Tests/Fixtures/expressions/array.test

index cfbca2c..e982534 100644 (file)
--- 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
index e405be5..d15b690 100644 (file)
@@ -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]: