diff --git a/src/js/static-net-filtering.js b/src/js/static-net-filtering.js index da4d3649d..efc393978 100644 --- a/src/js/static-net-filtering.js +++ b/src/js/static-net-filtering.js @@ -5167,8 +5167,7 @@ StaticNetFilteringEngine.prototype.matchAndFetchModifiers = function( toRemove.delete(key); } } - } - else if ( toAdd.size !== 0 ) { + } else if ( toAdd.size !== 0 ) { toAdd.clear(); if ( toRemove.size !== 1 ) { const entry = toRemove.get(''); @@ -5589,7 +5588,7 @@ StaticNetFilteringEngine.prototype.filterQuery = function(fctxt, out = []) { if ( qpos === -1 ) { return; } let hpos = url.indexOf('#', qpos + 1); if ( hpos === -1 ) { hpos = url.length; } - const params = new Map(); + const params = []; const query = url.slice(qpos + 1, hpos); for ( let i = 0; i < query.length; ) { let pos = query.indexOf('&', i); @@ -5598,14 +5597,14 @@ StaticNetFilteringEngine.prototype.filterQuery = function(fctxt, out = []) { i = pos + 1; pos = kv.indexOf('='); if ( pos !== -1 ) { - params.set(kv.slice(0, pos), kv.slice(pos + 1)); + params.push(kv.slice(0, pos), kv.slice(pos + 1)); } else { - params.set(kv, ''); + params.push(kv, ''); } } - const inParamCount = params.size; + const beforeParamCount = params.length; for ( const directive of directives ) { - if ( params.size === 0 ) { break; } + if ( params.length === 0 ) { break; } const isException = (directive.bits & ALLOW_REALM) !== 0; if ( isException && directive.value === '' ) { out.push(directive); @@ -5614,35 +5613,29 @@ StaticNetFilteringEngine.prototype.filterQuery = function(fctxt, out = []) { const { all, bad, name, not, re } = parseQueryPruneValue(directive); if ( bad ) { continue; } if ( all ) { - if ( isException === false ) { params.clear(); } + if ( isException === false ) { params.length = 0; } out.push(directive); break; } - if ( name !== undefined ) { - const value = params.get(name); - if ( not === false ) { - if ( value !== undefined ) { - if ( isException === false ) { params.delete(name); } - out.push(directive); - } - continue; - } - if ( value !== undefined ) { params.delete(name); } - if ( params.size !== 0 ) { - if ( isException === false ) { params.clear(); } - out.push(directive); - } - if ( value !== undefined ) { params.set(name, value); } - continue; - } - if ( re === undefined ) { continue; } let filtered = false; - for ( const [ key, raw ] of params ) { - let value = raw; - try { value = decodeURIComponent(value); } - catch { } - if ( re.test(`${key}=${value}`) === not ) { continue; } - if ( isException === false ) { params.delete(key); } + let matched = false; + let i = params.length; + while ( i > 0 ) { + i -= 2; + if ( name !== undefined ) { + matched = params[i] === name; + } else if ( re !== undefined ) { + const key = params[i+0]; + const raw = params[i+1]; + let value = raw; + try { value = decodeURIComponent(value); } + catch { } + matched = re.test(`${key}=${value}`); + } + if ( matched === not ) { continue; } + if ( isException === false ) { + params.splice(i, 2); + } filtered = true; } if ( filtered ) { @@ -5650,12 +5643,16 @@ StaticNetFilteringEngine.prototype.filterQuery = function(fctxt, out = []) { } } if ( out.length === 0 ) { return; } - if ( params.size !== inParamCount ) { + if ( params.length !== beforeParamCount ) { fctxt.redirectURL = url.slice(0, qpos); - if ( params.size !== 0 ) { - fctxt.redirectURL += '?' + Array.from(params).map(a => - a[1] === '' ? `${a[0]}=` : `${a[0]}=${a[1]}` - ).join('&'); + if ( params.length !== 0 ) { + const queryParts = []; + for ( let i = 0; i < params.length; i += 2 ) { + const key = params[i+0]; + const val = params[i+1]; + queryParts.push(val !== '' ? `${key}=${val}` : key); + } + fctxt.redirectURL += '?' + queryParts.join('&'); } if ( hpos !== url.length ) { fctxt.redirectURL += url.slice(hpos);