mirror of https://github.com/gorhill/uBlock.git
Mind that multiple `uritransform` may apply to a single request
Related issue: https://github.com/uBlockOrigin/uBlock-issues/issues/3125
This commit is contained in:
parent
9bff0c2f94
commit
2a5a444482
|
@ -5289,28 +5289,37 @@ FilterContainer.prototype.redirectRequest = function(redirectEngine, fctxt) {
|
||||||
FilterContainer.prototype.transformRequest = function(fctxt) {
|
FilterContainer.prototype.transformRequest = function(fctxt) {
|
||||||
const directives = this.matchAndFetchModifiers(fctxt, 'uritransform');
|
const directives = this.matchAndFetchModifiers(fctxt, 'uritransform');
|
||||||
if ( directives === undefined ) { return; }
|
if ( directives === undefined ) { return; }
|
||||||
const directive = directives[directives.length-1];
|
const redirectURL = new URL(fctxt.url);
|
||||||
if ( (directive.bits & ALLOW_REALM) !== 0 ) { return directives; }
|
const out = [];
|
||||||
if ( directive.refs instanceof Object === false ) { return; }
|
for ( const directive of directives ) {
|
||||||
|
if ( (directive.bits & ALLOW_REALM) !== 0 ) {
|
||||||
|
out.push(directive);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
const { refs } = directive;
|
const { refs } = directive;
|
||||||
|
if ( refs instanceof Object === false ) { continue; }
|
||||||
if ( refs.$cache === null ) {
|
if ( refs.$cache === null ) {
|
||||||
refs.$cache = sfp.parseReplaceValue(refs.value);
|
refs.$cache = sfp.parseReplaceValue(refs.value);
|
||||||
}
|
}
|
||||||
const cache = refs.$cache;
|
const cache = refs.$cache;
|
||||||
if ( cache === undefined ) { return; }
|
if ( cache === undefined ) { continue; }
|
||||||
const redirectURL = new URL(fctxt.url);
|
|
||||||
const before = `${redirectURL.pathname}${redirectURL.search}${redirectURL.hash}`;
|
const before = `${redirectURL.pathname}${redirectURL.search}${redirectURL.hash}`;
|
||||||
if ( cache.re.test(before) !== true ) { return; }
|
if ( cache.re.test(before) !== true ) { continue; }
|
||||||
const after = before.replace(cache.re, cache.replacement);
|
const after = before.replace(cache.re, cache.replacement);
|
||||||
if ( after === before ) { return; }
|
if ( after === before ) { continue; }
|
||||||
const hashPos = after.indexOf('#');
|
const hashPos = after.indexOf('#');
|
||||||
redirectURL.hash = hashPos !== -1 ? after.slice(hashPos) : '';
|
redirectURL.hash = hashPos !== -1 ? after.slice(hashPos) : '';
|
||||||
const afterMinusHash = hashPos !== -1 ? after.slice(0, hashPos) : after;
|
const afterMinusHash = hashPos !== -1 ? after.slice(0, hashPos) : after;
|
||||||
const searchPos = afterMinusHash.indexOf('?');
|
const searchPos = afterMinusHash.indexOf('?');
|
||||||
redirectURL.search = searchPos !== -1 ? afterMinusHash.slice(searchPos) : '';
|
redirectURL.search = searchPos !== -1 ? afterMinusHash.slice(searchPos) : '';
|
||||||
redirectURL.pathname = searchPos !== -1 ? after.slice(0, searchPos) : after;
|
redirectURL.pathname = searchPos !== -1 ? after.slice(0, searchPos) : after;
|
||||||
|
out.push(directive);
|
||||||
|
}
|
||||||
|
if ( out.length === 0 ) { return; }
|
||||||
|
if ( redirectURL.href !== fctxt.url ) {
|
||||||
fctxt.redirectURL = redirectURL.href;
|
fctxt.redirectURL = redirectURL.href;
|
||||||
return directives;
|
}
|
||||||
|
return out;
|
||||||
};
|
};
|
||||||
|
|
||||||
function parseRedirectRequestValue(directive) {
|
function parseRedirectRequestValue(directive) {
|
||||||
|
|
Loading…
Reference in New Issue