Allow `uritransform` to process the hash part of a URL

Related issue:
https://github.com/uBlockOrigin/uBlock-issues/issues/3084
This commit is contained in:
Raymond Hill 2024-01-18 11:36:40 -05:00
parent c9ceb561fc
commit b19094339f
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
1 changed files with 7 additions and 4 deletions

View File

@ -5309,13 +5309,16 @@ FilterContainer.prototype.transformRequest = function(fctxt) {
const cache = refs.$cache; const cache = refs.$cache;
if ( cache === undefined ) { return; } if ( cache === undefined ) { return; }
const redirectURL = new URL(fctxt.url); const redirectURL = new URL(fctxt.url);
const before = redirectURL.pathname + redirectURL.search; const before = `${redirectURL.pathname}${redirectURL.search}${redirectURL.hash}`;
if ( cache.re.test(before) !== true ) { return; } if ( cache.re.test(before) !== true ) { return; }
const after = before.replace(cache.re, cache.replacement); const after = before.replace(cache.re, cache.replacement);
if ( after === before ) { return; } if ( after === before ) { return; }
const searchPos = after.includes('?') && after.indexOf('?') || after.length; const hashPos = after.indexOf('#');
redirectURL.pathname = after.slice(0, searchPos); redirectURL.hash = hashPos !== -1 ? after.slice(hashPos) : '';
redirectURL.search = after.slice(searchPos); const afterMinusHash = hashPos !== -1 ? after.slice(0, hashPos) : after;
const searchPos = afterMinusHash.indexOf('?');
redirectURL.search = searchPos !== -1 ? afterMinusHash.slice(searchPos) : '';
redirectURL.pathname = searchPos !== -1 ? after.slice(0, searchPos) : after;
fctxt.redirectURL = redirectURL.href; fctxt.redirectURL = redirectURL.href;
return directives; return directives;
}; };