Skip to content

Commit

Permalink
Only already normalized CSS selectors can be fast path-compiled
Browse files Browse the repository at this point in the history
Related issue:
- uBlockOrigin/uBlock-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.
  • Loading branch information
gorhill committed Jul 13, 2023
1 parent b107040 commit 0da7e12
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions src/js/static-filtering-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = /(?:^|[^\\])(?:\\\\)*\\$/;
Expand Down Expand Up @@ -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})*$`
);
Expand Down

0 comments on commit 0da7e12

Please sign in to comment.