Skip to content

Commit 95dd93e

Browse files
author
Peter Dolak
committed
Fix unintended lstrip_blocks behavior. Fixes pallets#1138
Introduced in pallets#858. Tests will follow, also results of performance testing.
1 parent bff4893 commit 95dd93e

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/jinja2/lexer.py

+8-5
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,7 @@ def tokeniter(self, source, name, filename=None, state=None):
637637
balancing_stack = []
638638
lstrip_unless_re = self.lstrip_unless_re
639639
newlines_stripped = 0
640+
line_starting = True
640641

641642
while 1:
642643
# tokenizer loop
@@ -686,11 +687,11 @@ def tokeniter(self, source, name, filename=None, state=None):
686687
):
687688
# The start of text between the last newline and the tag.
688689
l_pos = text.rfind("\n") + 1
689-
690-
# If there's only whitespace between the newline and the
691-
# tag, strip it.
692-
if not lstrip_unless_re.search(text, l_pos):
693-
groups = (text[:l_pos],) + groups[1:]
690+
if l_pos > 0 or line_starting:
691+
# If there's only whitespace between the newline and the
692+
# tag, strip it.
693+
if not lstrip_unless_re.search(text, l_pos):
694+
groups = (text[:l_pos],) + groups[1:]
694695

695696
for idx, token in enumerate(tokens):
696697
# failure group
@@ -747,6 +748,8 @@ def tokeniter(self, source, name, filename=None, state=None):
747748
yield lineno, tokens, data
748749
lineno += data.count("\n")
749750

751+
line_starting = m.group()[-1:] == "\n"
752+
750753
# fetch new position into new variable so that we can check
751754
# if there is a internal parsing error which would result
752755
# in an infinite loop

0 commit comments

Comments
 (0)