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