1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-11-16 15:33:38 +01:00

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

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) {
} }