Fix regression with `important` filter option

Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/1732

The regression affect filter with the `important` option when
the following conditions were fulfilled:

- The filter pattern is pure hostname
- The filter has not one of the following options:
  - domain
  - denyallow
  - header
  - strict1p, strict3p
  - csp
  - removeparam
- There is a matching exception filter

Related commit:
- a2a8ef7e85

A related mocha test has been added in order to detect this
specific regression in the future through `make test`.
This commit is contained in:
Raymond Hill 2021-09-24 11:03:55 -04:00
parent 4edafa97a3
commit 1130746a9b
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
3 changed files with 29 additions and 9 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@gorhill/ubo-core",
"version": "0.1.10",
"version": "0.1.11",
"description": "To create a working instance of uBlock Origin's static network filtering engine",
"type": "module",
"main": "index.js",

View File

@ -232,6 +232,24 @@ describe('SNFE', () => {
await engine.deserialize(serialized);
});
});
describe('Filter matching', () => {
beforeEach(async () => {
engine = await module.StaticNetFilteringEngine.create();
});
it('should match block-important pure-hostname filter', async () => {
await engine.useLists([
{ name: 'test', raw: '@@||example.com^\n||example.com^$important' },
]);
engine.matchRequest({
originURL: 'https://www.example.com/',
type: 'main_frame',
url: 'https://www.example.com/',
});
});
});
});
}
});

View File

@ -3067,6 +3067,7 @@ class FilterCompiler {
break;
case this.parser.OPTTokenImportant:
if ( this.action === AllowAction ) { return false; }
this.optionUnitBits |= this.IMPORTANT_BIT;
this.action = BlockImportant;
break;
// Used by Adguard:
@ -3574,14 +3575,15 @@ class FilterCompiler {
}
}
FilterCompiler.prototype.DOMAIN_BIT = 0b00000001;
FilterCompiler.prototype.DENYALLOW_BIT = 0b00000010;
FilterCompiler.prototype.HEADER_BIT = 0b00000100;
FilterCompiler.prototype.STRICT_PARTY_BIT = 0b00001000;
FilterCompiler.prototype.CSP_BIT = 0b00010000;
FilterCompiler.prototype.QUERYPRUNE_BIT = 0b00100000;
FilterCompiler.prototype.REDIRECT_BIT = 0b01000000;
FilterCompiler.prototype.NOT_TYPE_BIT = 0b10000000;
FilterCompiler.prototype.DOMAIN_BIT = 0b000000001;
FilterCompiler.prototype.DENYALLOW_BIT = 0b000000010;
FilterCompiler.prototype.HEADER_BIT = 0b000000100;
FilterCompiler.prototype.STRICT_PARTY_BIT = 0b000001000;
FilterCompiler.prototype.CSP_BIT = 0b000010000;
FilterCompiler.prototype.QUERYPRUNE_BIT = 0b000100000;
FilterCompiler.prototype.REDIRECT_BIT = 0b001000000;
FilterCompiler.prototype.NOT_TYPE_BIT = 0b010000000;
FilterCompiler.prototype.IMPORTANT_BIT = 0b100000000;
FilterCompiler.prototype.FILTER_OK = 0;
FilterCompiler.prototype.FILTER_INVALID = 1;