Avoid endless loop with an assert in the diff parser.

This commit is contained in:
Dave Halter
2017-03-08 18:33:38 +01:00
parent 5c9769c5a3
commit b814a91f29

View File

@@ -281,6 +281,7 @@ class DiffParser(object):
Parses at least until the given line, but might just parse more until a
valid state is reached.
"""
last_until_line = 0
while until_line > self._nodes_stack.parsed_until_line:
node = self._try_parse_part(until_line)
nodes = self._get_children_nodes(node)
@@ -298,6 +299,12 @@ class DiffParser(object):
node.used_names
)
# Since the tokenizer sometimes has bugs, we cannot be sure that
# this loop terminates. Therefore assert that there's always a
# change.
assert last_until_line != self._nodes_stack.parsed_until_line, last_until_line
last_until_line = self._nodes_stack.parsed_until_line
def _get_children_nodes(self, node):
nodes = node.children
first_element = nodes[0]