Skip to content

Commit

Permalink
Fix depth for children of children
Browse files Browse the repository at this point in the history
  • Loading branch information
jg-rp committed Mar 18, 2024
1 parent 1690691 commit 672c172
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions jsonpath_rfc9535/segments.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,18 +145,20 @@ def _children(node: JSONPathNode) -> Iterable[JSONPathNode]:
while queue:
_node, depth = queue.popleft()

if depth > self.env.max_recursion_depth:
if depth >= self.env.max_recursion_depth:
raise JSONPathRecursionError(
"recursion limit exceeded", token=self.token
)

yield _node

# Visit child nodes now or queue them for later?
visit_children = random.choice([True, False]) # noqa: S311

for child in _children(_node):
if visit_children:
yield child
queue.extend([(child, depth + 1) for child in _children(child)])
queue.extend([(child, depth + 2) for child in _children(child)])
else:
queue.append((child, depth + 1))

Expand Down

0 comments on commit 672c172

Please sign in to comment.