From d21b9388f39ae11d0cc671d07d7d01ecdded7cfc Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Thu, 31 Oct 2019 12:43:33 -0400 Subject: [PATCH] Fix broken `csp=` filters when logger is opened Regression from: - https://github.com/gorhill/uBlock/commit/7971b223855d3afae2ca57565f27da0631a1b045 Related issue: - https://github.com/uBlockOrigin/uBlock-issues/issues/761 --- src/js/static-net-filtering.js | 66 +++++++++++++--------------------- 1 file changed, 24 insertions(+), 42 deletions(-) diff --git a/src/js/static-net-filtering.js b/src/js/static-net-filtering.js index 0ab80f246..a7d7ed69f 100644 --- a/src/js/static-net-filtering.js +++ b/src/js/static-net-filtering.js @@ -1447,12 +1447,9 @@ const FilterDataHolder = class { return true; } - matchAndFetchData(type, out) { - if ( this.dataType !== type ) { return false; } - if ( Array.isArray(out) ) { - out.push(this); - } - return true; + matchAndFetchData(type, callback) { + if ( this.dataType !== type ) { return; } + callback(this); } getData(type) { @@ -1594,16 +1591,12 @@ const FilterComposite = class extends FilterCollection { return true; } - matchAndFetchData(type, out) { + matchAndFetchData(type, callback) { if ( this.match() !== true ) { return false; } this.forEach(iunit => { const f = filterUnits[iunit]; if ( f.matchAndFetchData instanceof Function === false ) { return; } - if ( f.matchAndFetchData(type) === false ) { return; } - if ( Array.isArray(out) ) { - out.push(this); - } - return true; + f.matchAndFetchData(type, ( ) => { callback(this); }); }); } @@ -1880,10 +1873,12 @@ const FilterBucket = class extends FilterCollection { return false; } - matchAndFetchData(type, out) { + matchAndFetchData(type, callback) { const units = filterUnits; this.forEach(iunit => { - units[iunit].matchAndFetchData(type, out); + units[iunit].matchAndFetchData(type, f => { + callback(f, iunit); + }); }); } @@ -3118,41 +3113,28 @@ FilterContainer.prototype.realmMatchAndFetchData = function( if ( bucket01 === undefined && bucket11 === undefined ) { return false; } + const t = type, o = out; // to avoid jshint warning + const fdhr = (a, b, c) => new FilterDataHolderResult(a, b, c); const units = filterUnits; const tokenHashes = urlTokenizer.getTokens(bidiTrie); - const filters = []; - let i = 0, iunit, f; + let i = 0; for (;;) { const th = tokenHashes[i]; if ( th === 0 ) { return; } $tokenBeg = tokenHashes[i+1]; - if ( - (bucket01 !== undefined) && - (iunit = bucket01.get(th)) !== undefined - ) { - f = units[iunit]; - filters.length = 0; - f.matchAndFetchData(type, filters); - for ( f of filters ) { - out.set( - f.getData(type), - new FilterDataHolderResult(bits01, th, iunit) - ); - } + if ( bucket01 !== undefined ) bucket01: { + const iunit = bucket01.get(th); + if ( iunit === undefined ) { break bucket01; } + units[iunit].matchAndFetchData(type, (f, i) => { + o.set(f.getData(t), fdhr(bits01, th, i || iunit)); + }); } - if ( - (bucket11 !== undefined) && - (iunit = bucket11.get(th)) !== undefined - ) { - f = units[iunit]; - filters.length = 0; - f.matchAndFetchData(type, filters); - for ( f of filters ) { - out.set( - f.getData(type), - new FilterDataHolderResult(bits11, th, iunit) - ); - } + if ( bucket11 !== undefined ) bucket11: { + const iunit = bucket11.get(th); + if ( iunit === undefined ) { break bucket11; } + units[iunit].matchAndFetchData(t, (f, i) => { + o.set(f.getData(t), fdhr(bits11, th, i || iunit)); + }); } i += 2; }