Improve href-sanitizer scriptlet

Related issue:
https://github.com/uBlockOrigin/uBlock-issues/issues/3297

Mind that the sanitized URL can have Unicode characters beyond
ASCII.
This commit is contained in:
Raymond Hill 2024-07-10 12:43:36 -04:00
parent 569c8cbe04
commit 66e3a1ad47
No known key found for this signature in database
GPG key ID: 25E1490B761470C2

View file

@ -3477,7 +3477,7 @@ function hrefSanitizer(
};
const validateURL = text => {
if ( text === '' ) { return ''; }
if ( /[^\x21-\x7e]/.test(text) ) { return ''; }
if ( /[\x00-\x20\x7f]/.test(text) ) { return ''; }
try {
const url = new URL(text, document.location);
return url.href;