From a33f70cf201840951600acf50d92134e83b19972 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Mon, 16 Aug 2021 12:15:30 -0400 Subject: [PATCH] Provide compiler/selfie versions for snfe So as to allow nodejs usage to better deal with out of date serialization/compilation. Additionally, use FilterImportant() only when a "block-important" filter is stored in the "block" realm. --- src/js/static-net-filtering.js | 27 ++++++++++++++++----------- src/js/storage.js | 6 ++---- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/js/static-net-filtering.js b/src/js/static-net-filtering.js index a408ead76..e19edbcfb 100644 --- a/src/js/static-net-filtering.js +++ b/src/js/static-net-filtering.js @@ -3431,11 +3431,6 @@ class FilterCompiler { units.push(FilterAnchorRight.compile()); } - // Important - if ( (this.action & Important) !== 0 ) { - units.push(FilterImportant.compile()); - } - // Strict partiness if ( this.strictParty !== 0 ) { units.push(FilterStrictParty.compile(this)); @@ -3469,11 +3464,12 @@ class FilterCompiler { this.action = (this.action & ~ActionBitsMask) | ModifyAction; } - const fdata = units.length === 1 - ? units[0] - : FilterCompositeAll.compile(units); - - this.compileToAtomicFilter(fdata, writer); + this.compileToAtomicFilter( + units.length === 1 + ? units[0] + : FilterCompositeAll.compile(units), + writer + ); // Add block-important filters to the block realm, so as to avoid // to unconditionally match against the block-important realm for @@ -3483,7 +3479,11 @@ class FilterCompiler { // meant to override. if ( (this.action & BlockImportant) !== 0 ) { this.action &= ~Important; - this.compileToAtomicFilter(fdata, writer); + units.push(FilterImportant.compile()); + this.compileToAtomicFilter( + FilterCompositeAll.compile(units), + writer + ); } } @@ -3537,6 +3537,9 @@ FilterCompiler.prototype.FILTER_UNSUPPORTED = 2; /******************************************************************************/ const FilterContainer = function() { + this.compilerVersion = '1'; + this.selfieVersion = '1'; + this.MAX_TOKEN_LENGTH = MAX_TOKEN_LENGTH; this.optimizeTimerId = undefined; // As long as CategoryCount is reasonably low, we will use an array to @@ -3768,6 +3771,7 @@ FilterContainer.prototype.toSelfie = function(storage, path) { storage.put( `${path}/main`, JSON.stringify({ + version: this.selfieVersion, processedFilterCount: this.processedFilterCount, acceptedCount: this.acceptedCount, rejectedCount: this.rejectedCount, @@ -3831,6 +3835,7 @@ FilterContainer.prototype.fromSelfie = function(storage, path) { } catch (ex) { } if ( selfie instanceof Object === false ) { return false; } + if ( selfie.version !== this.selfieVersion ) { return false; } this.processedFilterCount = selfie.processedFilterCount; this.acceptedCount = selfie.acceptedCount; this.rejectedCount = selfie.rejectedCount; diff --git a/src/js/storage.js b/src/js/storage.js index 3be81945e..f2269bf74 100644 --- a/src/js/storage.js +++ b/src/js/storage.js @@ -866,10 +866,8 @@ self.addEventListener('hiddenSettingsChanged', ( ) => { this.badLists.has(assetKey) === false ) { const compiledDetails = await io.get(compiledPath); - if ( - parseInt(compiledDetails.content, 10) === - this.systemSettings.compiledMagic - ) { + const compilerVersion = `${this.systemSettings.compiledMagic}\n`; + if ( compiledDetails.content.startsWith(compilerVersion) ) { compiledDetails.assetKey = assetKey; return compiledDetails; }