mirror of https://github.com/gorhill/uBlock.git
Validate result type of XPath expressions
Related issue: https://github.com/uBlockOrigin/uBlock-issues/issues/3403 To ensure XPath expressions not meant to return a nodeset are discarded at compile time.
This commit is contained in:
parent
447476ab9b
commit
c746633693
|
@ -4116,9 +4116,11 @@ class ExtSelectorCompiler {
|
||||||
compileXpathExpression(s) {
|
compileXpathExpression(s) {
|
||||||
const r = this.unquoteString(s);
|
const r = this.unquoteString(s);
|
||||||
if ( r.i !== s.length ) { return; }
|
if ( r.i !== s.length ) { return; }
|
||||||
if ( globalThis.document instanceof Object === false ) { return r.s; }
|
const doc = globalThis.document;
|
||||||
|
if ( doc instanceof Object === false ) { return r.s; }
|
||||||
try {
|
try {
|
||||||
globalThis.document.createExpression(r.s, null);
|
const expr = doc.createExpression(r.s, null);
|
||||||
|
expr.evaluate(doc, XPathResult.ANY_UNORDERED_NODE_TYPE);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue