XPathRule doesn't check the type of the nodes returned by an XPath expression:
final List<ElementNode> nodes = xpathExpression.evaluate(xpathDynamicContext); /* Map List of Saxon Nodes -> List of AST Nodes, which were detected to match the XPath expression (i.e. violation found) */ final List<Node> results = new ArrayList<>(); for (final ElementNode elementNode : nodes) { results.add((Node) elementNode.getUnderlyingNode()); }The assignment of the result of xpathExpression::evaluate
to List<ElementNode>
line 86 is unchecked, it's actually a list of the more general Item
. So when getting a node line 93, the routine will fail with ClassCastException
if the element is not actually an ElementNode
.
This is not completely outlandish: eg 1+1
is a valid XPath expression that doesn't yield an ElementNode, and so is /
(a single slash), which should yield a document node (see #1938)
We should at least ensure that the type of each element is correct
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4