From 672c172be6cb6a73909ff76b68c8291d3ecd626d Mon Sep 17 00:00:00 2001 From: James Prior Date: Mon, 18 Mar 2024 08:28:15 +0000 Subject: [PATCH] Fix depth for children of children --- jsonpath_rfc9535/segments.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/jsonpath_rfc9535/segments.py b/jsonpath_rfc9535/segments.py index 057a76b..2e0f7e5 100644 --- a/jsonpath_rfc9535/segments.py +++ b/jsonpath_rfc9535/segments.py @@ -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))