Skip to content
Myr

Fix unintended lstrip_blocks behavior. Fixes #1138

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Introduced in #858. Tests will follow, also results of performance testing.

authored by Peter Dolak · committed by Peter Dolak · parent 4a70cd4 · Browse files · 1 file+8 added−5 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+8 added−5 removed

  • other:+8 added−5 removed

1 file+8 added−5 removed

modified:src/jinja2/lexer.py+8 added-5 removed
680 unmodified lines
681 source_length = len(source)682 balancing_stack = []683 lstrip_unless_re = self.lstrip_unless_re684 newlines_stripped = 0685 line_starting = True686687 while 1:688 # tokenizer loop689 for regex, tokens, new_state in statetokens:
41 unmodified lines
731 and not m.groupdict().get(TOKEN_VARIABLE_BEGIN)732 ):733 # The start of text between the last newline and the tag.734 l_pos = text.rfind("\n") + 1735 if l_pos > 0 or line_starting:736 # If there's only whitespace between the newline and the737 # tag, strip it.738 if not lstrip_unless_re.search(text, l_pos):739 groups = (text[:l_pos],) + groups[1:]740735 # If there's only whitespace between the newline and the736 # tag, strip it.737 if not lstrip_unless_re.search(text, l_pos):738 groups = (text[:l_pos],) + groups[1:]739741 for idx, token in enumerate(tokens):742 # failure group743 if token.__class__ is Failure:744 raise token(lineno, filename)
49 unmodified lines
794 if data or tokens not in ignore_if_empty:795 yield lineno, tokens, data796 lineno += data.count("\n")797798 line_starting = m.group()[-1:] == "\n"799800 # fetch new position into new variable so that we can check801 # if there is a internal parsing error which would result802 # in an infinite loop803 pos2 = m.end()
45 unmodified lines