1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-07-05 11:37:01 +02:00

[mv3] Fix conversion of :xpath procedural filters

Procedural filters with `:xpath` operator were silently rejected
at conversion time because the parser was failing to evaluate the
xpath expression due to the absence of a `document` object in
nodejs.

If `document` object is not present, the parser will assume the
xpath expression is valid.
This commit is contained in:
Raymond Hill 2024-01-22 10:57:48 -05:00
parent 46e19e4f7f
commit f1889b02ee
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
4 changed files with 13 additions and 3 deletions

View File

@ -566,6 +566,13 @@ class PSelectorRoot extends PSelector {
}
return [];
}
exec(input) {
try {
return super.exec(input);
} catch (ex) {
}
return [];
}
}
/******************************************************************************/

View File

@ -299,10 +299,10 @@ function addToDNR(context, list) {
if ( parser.isComment() ) {
if ( line === `!#trusted on ${context.secret}` ) {
parser.trustedSource = true;
parser.options.trustedSource = true;
context.trustedSource = true;
} else if ( line === `!#trusted off ${context.secret}` ) {
parser.trustedSource = false;
parser.options.trustedSource = false;
context.trustedSource = false;
}
continue;
@ -312,6 +312,8 @@ function addToDNR(context, list) {
if ( parser.hasError() ) {
if ( parser.astError === sfp.AST_ERROR_OPTION_EXCLUDED ) {
context.invalid.add(`Incompatible with DNR: ${line}`);
} else {
context.invalid.add(`Rejected filter: ${line}`);
}
continue;
}

View File

@ -4022,6 +4022,7 @@ class ExtSelectorCompiler {
compileXpathExpression(s) {
const r = this.unquoteString(s);
if ( r.i !== s.length ) { return; }
if ( globalThis.document instanceof Object === false ) { return r.s; }
try {
globalThis.document.createExpression(r.s, null);
} catch (e) {

View File

@ -4571,7 +4571,7 @@ FilterContainer.prototype.dnrFromCompiled = function(op, context, ...args) {
}
break;
case 'uritransform': {
dnrAddRuleError(rule, `Unsupported uritransform=${rule.__modifierValue}`);
dnrAddRuleError(rule, `Incompatible with DNR: uritransform=${rule.__modifierValue}`);
break;
}
default: