From f15a9f76287ea3083488672b17535ea63470f2ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Henrique?= Date: Wed, 4 Sep 2019 15:53:02 -0300 Subject: [PATCH] Prevent XPath from returning the same node multiple times in Python3 --- runtime/Python3/src/antlr4/xpath/XPath.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/runtime/Python3/src/antlr4/xpath/XPath.py b/runtime/Python3/src/antlr4/xpath/XPath.py index 07fcd0b54..4d3a4f56f 100644 --- a/runtime/Python3/src/antlr4/xpath/XPath.py +++ b/runtime/Python3/src/antlr4/xpath/XPath.py @@ -261,6 +261,11 @@ class XPath(object): # e.g., //func/*/stat might have a token node for which # we can't go looking for stat nodes. matching = element.evaluate(node) + + # See issue antlr#370 - Prevents XPath from returning the + # same node multiple times + matching = filter(lambda m: m not in work_next, matching) + work_next.extend(matching) work = work_next