From 0da7e12ea4a04a473ccbc04ade65593d985b5b3b Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Thu, 13 Jul 2023 17:53:24 -0400 Subject: [PATCH] Only already normalized CSS selectors can be fast path-compiled Related issue: - https://github.com/uBlockOrigin/uBlock-issues/issues/2730 CSS selectors used in cosmetic filtering are normalized in order to ignore non-functional differences. For instance: example.org##body p example.org#@#body p The first cosmetic filter should be excepted by the second one, but this was not the case because the fast path use to compile common CSS selectors was not causing normalization to take place. The fix is to ensure that the fast path used to compile most common CSS selectors is taken only when in presence of already normalized CSS selectors. --- src/js/static-filtering-parser.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/js/static-filtering-parser.js b/src/js/static-filtering-parser.js index 34356d0934824..77f6cc2a3cda9 100644 --- a/src/js/static-filtering-parser.js +++ b/src/js/static-filtering-parser.js @@ -793,7 +793,6 @@ export class AstFilterParser { this.reHostnameLabel = /[^.]+/g; this.reResponseheaderPattern = /^\^responseheader\(.*\)$/; this.rePatternScriptletJsonArgs = /^\{.*\}$/; - // TODO: mind maxTokenLength this.reGoodRegexToken = /[^\x01%0-9A-Za-z][%0-9A-Za-z]{7,}|[^\x01%0-9A-Za-z][%0-9A-Za-z]{1,6}[^\x01%0-9A-Za-z]/; this.reBadCSP = /(?:=|;)\s*report-(?:to|uri)\b/; this.reOddTrailingEscape = /(?:^|[^\\])(?:\\\\)*\\$/; @@ -3028,7 +3027,7 @@ class ExtSelectorCompiler { `${cssClassOrId}(?:${cssClassOrId})*(?:${cssAttribute})*` + '|' + `${cssAttribute}(?:${cssAttribute})*` + ')'; - const cssCombinator = '(?:\\s+|\\s*[+>~]\\s*)'; + const cssCombinator = '(?: | [+>~] )'; this.reCommonSelector = new RegExp( `^${cssSimple}(?:${cssCombinator}${cssSimple})*$` );