summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sphinx/util/nodes.py3
-rw-r--r--tests/test_util_nodes.py4
2 files changed, 7 insertions, 0 deletions
diff --git a/sphinx/util/nodes.py b/sphinx/util/nodes.py
index a59606044..484681368 100644
--- a/sphinx/util/nodes.py
+++ b/sphinx/util/nodes.py
@@ -68,6 +68,9 @@ class NodeMatcher:
if self.classes and not isinstance(node, self.classes):
return False
+ if self.attrs and isinstance(node, nodes.Text):
+ return False
+
for key, value in self.attrs.items():
if key not in node:
return False
diff --git a/tests/test_util_nodes.py b/tests/test_util_nodes.py
index 2fab10c1c..04b437a4f 100644
--- a/tests/test_util_nodes.py
+++ b/tests/test_util_nodes.py
@@ -82,6 +82,10 @@ def test_NodeMatcher():
matcher = NodeMatcher(nodes.title)
assert len(doctree.traverse(matcher)) == 0
+ # search with Any does not match to Text node
+ matcher = NodeMatcher(blah=Any)
+ assert len(doctree.traverse(matcher)) == 0
+
@pytest.mark.parametrize(
'rst,node_cls,count',