Fixed another bug with line comments
authorArmin Ronacher <armin.ronacher@active-4.com>
Wed, 1 Apr 2009 17:16:25 +0000 (19:16 +0200)
committerArmin Ronacher <armin.ronacher@active-4.com>
Wed, 1 Apr 2009 17:16:25 +0000 (19:16 +0200)
--HG--
branch : trunk

jinja2/lexer.py
tests/test_parser.py

index 8f6393270d311b95f186084cdda58f5f4935be08..3a925bb6ee66292382b5cc8744e636405a7e498d 100644 (file)
@@ -144,7 +144,7 @@ def compile_rules(environment):
         (len(environment.block_start_string), 'block',
          e(environment.block_start_string)),
         (len(environment.variable_start_string), 'variable',
-         e(environment.variable_start_string)),
+         e(environment.variable_start_string))
     ]
 
     if environment.line_statement_prefix is not None:
@@ -152,7 +152,7 @@ def compile_rules(environment):
                       r'^\s*' + e(environment.line_statement_prefix)))
     if environment.line_comment_prefix is not None:
         rules.append((len(environment.line_comment_prefix), 'linecomment',
-                      r'(?:^|(?<!\S))\s*' + e(environment.line_comment_prefix)))
+                      r'(?:^|(?<=\S))[^\S\r\n]*' + e(environment.line_comment_prefix)))
 
     return [x[1:] for x in sorted(rules, reverse=True)]
 
index 9ee6003732f70b86bf1eb4a774100ed3c3628bf3..8d39ab0f2a9df049b12d44e7f01da25d0c10b0a8 100644 (file)
@@ -107,7 +107,7 @@ def test_line_syntax_priority():
     # XXX: why is the whitespace there in front of the newline?
     env = Environment('{%', '%}', '${', '}', '/*', '*/', '##', '#')
     tmpl = env.from_string(LINE_SYNTAX_PRIORITY1)
-    assert tmpl.render(seq=[1, 2]).strip() == '* 1 \n* 2'
+    assert tmpl.render(seq=[1, 2]).strip() == '* 1\n* 2'
     env = Environment('{%', '%}', '${', '}', '/*', '*/', '#', '##')
     tmpl = env.from_string(LINE_SYNTAX_PRIORITY2)
-    assert tmpl.render(seq=[1, 2]).strip() == '* 1 \n* 2'
+    assert tmpl.render(seq=[1, 2]).strip() == '* 1\n* 2'