mirror of https://github.com/gorhill/uBlock.git
Do not generate DNR block rule for `redirect=` filters
DNR API does not support block-then-redirect concept, hence no point in generating a DNR block rule for `redirect=` filters. Additionally, better handle orphaned filter anchors (`||`, `|`).
This commit is contained in:
parent
3b63fef848
commit
a0a23085ed
|
@ -210,6 +210,7 @@ function addToDNR(context, list) {
|
|||
sfp.utils.preparser.prune(list.text, env)
|
||||
);
|
||||
const parser = new sfp.AstFilterParser({
|
||||
toDNR: true,
|
||||
nativeCssHas: env.includes('native_css_has'),
|
||||
badTypes: [ sfp.NODE_TYPE_NET_OPTION_NAME_REDIRECTRULE ],
|
||||
});
|
||||
|
|
|
@ -697,6 +697,7 @@ export class AstFilterParser {
|
|||
this.hasUnicode = false;
|
||||
this.hasUppercase = false;
|
||||
// Options
|
||||
this.options = options;
|
||||
this.interactive = options.interactive || false;
|
||||
this.expertMode = options.expertMode || false;
|
||||
this.badTypes = new Set(options.badTypes || []);
|
||||
|
@ -1478,7 +1479,7 @@ export class AstFilterParser {
|
|||
|
||||
// Left anchor
|
||||
if ( c1st === 0x7C /* '|' */ ) {
|
||||
if ( pattern.length > 2 && c2nd === 0x7C /* '|' */ ) {
|
||||
if ( c2nd === 0x7C /* '|' */ ) {
|
||||
const type = this.isTokenCharCode(pattern.charCodeAt(2) || 0)
|
||||
? NODE_TYPE_NET_PATTERN_LEFT_HNANCHOR
|
||||
: NODE_TYPE_IGNORE;
|
||||
|
@ -1486,10 +1487,9 @@ export class AstFilterParser {
|
|||
if ( type === NODE_TYPE_NET_PATTERN_LEFT_HNANCHOR ) {
|
||||
this.addFlags(AST_FLAG_NET_PATTERN_LEFT_HNANCHOR);
|
||||
}
|
||||
prev = this.linkRight(prev, next);
|
||||
patternBeg += 2;
|
||||
pattern = pattern.slice(2);
|
||||
} else if ( pattern.length > 1 ) {
|
||||
} else {
|
||||
const type = this.isTokenCharCode(c2nd)
|
||||
? NODE_TYPE_NET_PATTERN_LEFT_ANCHOR
|
||||
: NODE_TYPE_IGNORE;
|
||||
|
@ -1497,14 +1497,17 @@ export class AstFilterParser {
|
|||
if ( type === NODE_TYPE_NET_PATTERN_LEFT_ANCHOR ) {
|
||||
this.addFlags(AST_FLAG_NET_PATTERN_LEFT_ANCHOR);
|
||||
}
|
||||
prev = this.linkRight(prev, next);
|
||||
patternBeg += 1;
|
||||
pattern = pattern.slice(1);
|
||||
}
|
||||
prev = this.linkRight(prev, next);
|
||||
if ( patternBeg === patternEnd ) {
|
||||
this.addNodeFlags(next, NODE_FLAG_IGNORE);
|
||||
}
|
||||
}
|
||||
|
||||
// Right anchor
|
||||
if ( clast === 0x7C /* | */ && pattern.length >= 2 ) {
|
||||
if ( exCharCodeAt(pattern, -1) === 0x7C /* | */ ) {
|
||||
const type = exCharCodeAt(pattern, -2) !== 0x2A /* * */
|
||||
? NODE_TYPE_NET_PATTERN_RIGHT_ANCHOR
|
||||
: NODE_TYPE_IGNORE;
|
||||
|
@ -1514,6 +1517,9 @@ export class AstFilterParser {
|
|||
}
|
||||
patternEnd -= 1;
|
||||
pattern = pattern.slice(0, -1);
|
||||
if ( patternEnd === patternBeg ) {
|
||||
this.addNodeFlags(tail, NODE_FLAG_IGNORE);
|
||||
}
|
||||
}
|
||||
|
||||
// Ignore pointless leading wildcards
|
||||
|
|
|
@ -3817,6 +3817,8 @@ class FilterCompiler {
|
|||
parsedBlock.modifyType = undefined;
|
||||
parsedBlock.optionUnitBits &= ~this.REDIRECT_BIT;
|
||||
parsedBlock.compileToFilter(writer);
|
||||
// Do not generate block rule when compiling to DNR ruleset
|
||||
if ( parser.options.toDNR ) { return true; }
|
||||
}
|
||||
|
||||
this.compileToFilter(writer);
|
||||
|
|
Loading…
Reference in New Issue