Improve `href-sanitizer` sciptlet

Tolerate unexpected spaces in extracted URL parameters.

Related feedback:
https://github.com/uBlockOrigin/uBlock-issues/issues/3297#issuecomment-2283806183
This commit is contained in:
Raymond Hill 2024-08-12 13:45:46 -04:00
parent 1822d1503f
commit db3dc69bcc
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
1 changed files with 4 additions and 1 deletions

View File

@ -3551,9 +3551,12 @@ function hrefSanitizer(
const end = recursive ? source.indexOf('?', 1) : source.length; const end = recursive ? source.indexOf('?', 1) : source.length;
try { try {
const url = new URL(href, document.location); const url = new URL(href, document.location);
const value = url.searchParams.get(source.slice(1, end)); let value = url.searchParams.get(source.slice(1, end));
if ( value === null ) { return href } if ( value === null ) { return href }
if ( recursive ) { return extractParam(value, source.slice(end)); } if ( recursive ) { return extractParam(value, source.slice(end)); }
if ( value.includes(' ') ) {
value = value.replace(/ /g, '%20');
}
return value; return value;
} catch(x) { } catch(x) {
} }