1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-11-02 00:42:45 +01:00

Fix bad pruning logic

Related feedback:
- https://github.com/uBlockOrigin/uBlock-issues/issues/760#issuecomment-720140135
This commit is contained in:
Raymond Hill 2020-11-02 04:51:40 -05:00
parent 76ea126c12
commit f76471f56b
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2

View File

@ -3557,9 +3557,11 @@ FilterContainer.prototype.matchString = function(fctxt, modifiers = 0) {
FilterContainer.prototype.filterQuery = function(fctxt) { FilterContainer.prototype.filterQuery = function(fctxt) {
const directives = this.matchAndFetchModifiers(fctxt, 'queryprune'); const directives = this.matchAndFetchModifiers(fctxt, 'queryprune');
if ( directives === undefined ) { return; } if ( directives === undefined ) { return; }
const params = []; const url = fctxt.url;
let qpos = url.indexOf('?');
if ( qpos === -1 ) { return; }
const params = new self.URLSearchParams(url.slice(qpos + 1));
const out = []; const out = [];
const url = new URL(fctxt.url);
for ( const directive of directives ) { for ( const directive of directives ) {
const modifier = directive.modifier; const modifier = directive.modifier;
if ( modifier.cache === undefined ) { if ( modifier.cache === undefined ) {
@ -3570,20 +3572,21 @@ FilterContainer.prototype.filterQuery = function(fctxt) {
} }
const re = modifier.cache; const re = modifier.cache;
let filtered = false; let filtered = false;
for ( const [ key, value ] of url.searchParams ) { for ( const [ key, value ] of params ) {
if ( re.test(`${key}=${value}`) ) { if ( re.test(`${key}=${value}`) === false ) { continue; }
filtered = true; params.delete(key);
} else { filtered = true;
params.push(`${key}=${encodeURIComponent(value)}`);
}
} }
if ( filtered ) { if ( filtered ) {
out.push(directive); out.push(directive);
} }
} }
if ( out.length === 0 ) { return; } if ( out.length === 0 ) { return; }
url.search = params.length !== 0 ? `?${params.join('&')}` : ''; fctxt.redirectURL = url.slice(0, qpos);
fctxt.redirectURL = url.href; const query = params.toString();
if ( query !== '' ) {
fctxt.redirectURL += '?' + query;
}
return out; return out;
}; };