Skip to content

Commit

Permalink
Allow uritransform to process the hash part of a URL
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhill committed Jan 18, 2024
1 parent c9ceb56 commit b190943
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/js/static-net-filtering.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down

0 comments on commit b190943

Please sign in to comment.