From 1130746a9b826b1739627114c16b4e9995a53582 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Fri, 24 Sep 2021 11:03:55 -0400 Subject: [PATCH] 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: - https://github.com/gorhill/uBlock/commit/a2a8ef7e851471b3902ff1606f9266bfd93669ed A related mocha test has been added in order to detect this specific regression in the future through `make test`. --- platform/npm/package.json | 2 +- platform/npm/tests/snfe.js | 18 ++++++++++++++++++ src/js/static-net-filtering.js | 18 ++++++++++-------- 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/platform/npm/package.json b/platform/npm/package.json index 774b32a37..dd46f941a 100644 --- a/platform/npm/package.json +++ b/platform/npm/package.json @@ -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", diff --git a/platform/npm/tests/snfe.js b/platform/npm/tests/snfe.js index 0ce13a036..f45969502 100644 --- a/platform/npm/tests/snfe.js +++ b/platform/npm/tests/snfe.js @@ -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/', + }); + }); + }); }); } }); diff --git a/src/js/static-net-filtering.js b/src/js/static-net-filtering.js index f3fee435d..a9aec2a9b 100644 --- a/src/js/static-net-filtering.js +++ b/src/js/static-net-filtering.js @@ -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;