1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-09-15 07:22:28 +02:00

Avoid testing sheet-selectability when filter is hinted as procedural

uBO support's `#?#`, which in AdGuard and ABP means that a
cosmetic filter is procedural.

However, uBO interprets this syntax as "probably procedural"
and will use the filter in a declarative way if the filter
is found to be stylesheet-compatible.

In reality though, the likelihood that a "probably procedural"
filter is sheet-selectable is very low, so treating the filter
as procedural a priori help saves pointless tests against
sheet-selectability when using lists primarily designed for
AdGuard or ABP.
This commit is contained in:
Raymond Hill 2021-10-29 08:33:55 -04:00
parent 24fe6f2cfc
commit 8f2e1b4d84
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2

View File

@ -1351,7 +1351,7 @@ Parser.prototype.SelectorCompiler = class {
]);
}
compile(raw, isProcedural, out) {
compile(raw, asProcedural, out) {
// https://github.com/gorhill/uBlock/issues/952
// Find out whether we are dealing with an Adguard-specific cosmetic
// filter, and if so, translate it if supported, or discard it if not
@ -1367,15 +1367,10 @@ Parser.prototype.SelectorCompiler = class {
out.raw = raw;
}
let extendedSyntax = false;
// Can be used in a declarative CSS rule?
if ( this.sheetSelectable(raw) ) {
extendedSyntax = this.reExtendedSyntax.test(raw);
if ( (extendedSyntax || isProcedural) === false ) {
out.compiled = raw;
return true;
}
if ( asProcedural === false && this.sheetSelectable(raw) ) {
out.compiled = raw;
return true;
}
// We rarely reach this point -- majority of selectors are plain
@ -1388,7 +1383,7 @@ Parser.prototype.SelectorCompiler = class {
// Note: extended selector syntax has been deprecated in ABP, in
// favor of the procedural one (i.e. `:operator(...)`).
// See https://issues.adblockplus.org/ticket/5287
if ( extendedSyntax ) {
if ( asProcedural && this.reExtendedSyntax.test(raw) ) {
let matches;
while ( (matches = this.reExtendedSyntaxParser.exec(raw)) !== null ) {
const operator = this.normalizedExtendedSyntaxOperators.get(matches[1]);
@ -1397,7 +1392,7 @@ Parser.prototype.SelectorCompiler = class {
operator + '(' + matches[3] + ')' +
raw.slice(matches.index + matches[0].length);
}
return this.compile(raw, isProcedural, out);
return this.compile(raw, true, out);
}
// Procedural selector?