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.
This commit is contained in:
Raymond Hill 2023-07-13 17:53:24 -04:00
parent b107040d89
commit 0da7e12ea4
No known key found for this signature in database
GPG key ID: 25E1490B761470C2

View file

@ -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})*$`
);