From 8f2e1b4d847d8f9eaf2a97cc09b69607f8fc9535 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Fri, 29 Oct 2021 08:33:55 -0400 Subject: [PATCH] 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. --- src/js/static-filtering-parser.js | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/js/static-filtering-parser.js b/src/js/static-filtering-parser.js index e804529eb..6e57710a7 100644 --- a/src/js/static-filtering-parser.js +++ b/src/js/static-filtering-parser.js @@ -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?