mirror of https://github.com/gorhill/uBlock.git
Do not redirect when no query parameters are removed
Related issue: - https://github.com/uBlockOrigin/uBlock-issues/issues/1626
This commit is contained in:
parent
40c75b63e6
commit
8877ea290e
|
@ -4268,6 +4268,9 @@ FilterContainer.compareRedirectRequests = function(a, b) {
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
|
// https://github.com/uBlockOrigin/uBlock-issues/issues/1626
|
||||||
|
// Do not redirect when the number of query parameters does not change.
|
||||||
|
|
||||||
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; }
|
||||||
|
@ -4277,6 +4280,7 @@ FilterContainer.prototype.filterQuery = function(fctxt) {
|
||||||
let hpos = url.indexOf('#', qpos + 1);
|
let hpos = url.indexOf('#', qpos + 1);
|
||||||
if ( hpos === -1 ) { hpos = url.length; }
|
if ( hpos === -1 ) { hpos = url.length; }
|
||||||
const params = new Map(new self.URLSearchParams(url.slice(qpos + 1, hpos)));
|
const params = new Map(new self.URLSearchParams(url.slice(qpos + 1, hpos)));
|
||||||
|
const inParamCount = params.size;
|
||||||
const out = [];
|
const out = [];
|
||||||
for ( const directive of directives ) {
|
for ( const directive of directives ) {
|
||||||
if ( params.size === 0 ) { break; }
|
if ( params.size === 0 ) { break; }
|
||||||
|
@ -4322,14 +4326,16 @@ FilterContainer.prototype.filterQuery = function(fctxt) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( out.length === 0 ) { return; }
|
if ( out.length === 0 ) { return; }
|
||||||
fctxt.redirectURL = url.slice(0, qpos);
|
if ( params.size !== inParamCount ) {
|
||||||
if ( params.size !== 0 ) {
|
fctxt.redirectURL = url.slice(0, qpos);
|
||||||
fctxt.redirectURL += '?' + Array.from(params).map(a =>
|
if ( params.size !== 0 ) {
|
||||||
a[1] === '' ? a[0] : `${a[0]}=${encodeURIComponent(a[1])}`
|
fctxt.redirectURL += '?' + Array.from(params).map(a =>
|
||||||
).join('&');
|
a[1] === '' ? a[0] : `${a[0]}=${encodeURIComponent(a[1])}`
|
||||||
}
|
).join('&');
|
||||||
if ( hpos !== url.length ) {
|
}
|
||||||
fctxt.redirectURL += url.slice(hpos);
|
if ( hpos !== url.length ) {
|
||||||
|
fctxt.redirectURL += url.slice(hpos);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue