From b19094339f63fdec3e932491a2b755ff95344bcd Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Thu, 18 Jan 2024 11:36:40 -0500 Subject: [PATCH] Allow `uritransform` to process the hash part of a URL Related issue: https://github.com/uBlockOrigin/uBlock-issues/issues/3084 --- src/js/static-net-filtering.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/js/static-net-filtering.js b/src/js/static-net-filtering.js index f0d8822b2..d4a6e303e 100644 --- a/src/js/static-net-filtering.js +++ b/src/js/static-net-filtering.js @@ -5309,13 +5309,16 @@ FilterContainer.prototype.transformRequest = function(fctxt) { const cache = refs.$cache; if ( cache === undefined ) { return; } 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; } const after = before.replace(cache.re, cache.replacement); if ( after === before ) { return; } - const searchPos = after.includes('?') && after.indexOf('?') || after.length; - redirectURL.pathname = after.slice(0, searchPos); - redirectURL.search = after.slice(searchPos); + const hashPos = after.indexOf('#'); + redirectURL.hash = hashPos !== -1 ? after.slice(hashPos) : ''; + 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; return directives; };