mirror of
https://github.com/gorhill/uBlock.git
synced 2026-03-11 09:04:36 +00:00
Fix regression in href-sanitizer scriptlet
Related feedback: https://github.com/uBlockOrigin/uBlock-issues/issues/2531#issuecomment-2561968581 Regression from: https://github.com/gorhill/uBlock/commit/9bf8d53ebe
This commit is contained in:
parent
f7fa3139af
commit
42638f0e44
1 changed files with 21 additions and 7 deletions
|
|
@ -91,6 +91,20 @@ function hrefSanitizer(
|
|||
}
|
||||
return '';
|
||||
};
|
||||
const extractParam = (href, source) => {
|
||||
if ( Boolean(source) === false ) { return href; }
|
||||
const recursive = source.includes('?', 1);
|
||||
const end = recursive ? source.indexOf('?', 1) : source.length;
|
||||
try {
|
||||
const url = new URL(href, document.location);
|
||||
let value = url.searchParams.get(source.slice(1, end));
|
||||
if ( value === null ) { return href }
|
||||
if ( recursive ) { return extractParam(value, source.slice(end)); }
|
||||
return value;
|
||||
} catch(x) {
|
||||
}
|
||||
return href;
|
||||
};
|
||||
const extractURL = (elem, source) => {
|
||||
if ( /^\[.*\]$/.test(source) ) {
|
||||
return elem.getAttribute(source.slice(1,-1).trim()) || '';
|
||||
|
|
@ -101,13 +115,13 @@ function hrefSanitizer(
|
|||
.replace(/[^\x21-\x7e]+$/, '') // remove trailing invalid characters
|
||||
;
|
||||
}
|
||||
if ( source.startsWith('?') ) {
|
||||
const steps = source.replace(/(\S)\?/g, '\\1?').split(/\s+/);
|
||||
const url = urlSkip(elem.href, false, steps);
|
||||
if ( url === undefined ) { return; }
|
||||
return url.replace(/ /g, '%20');
|
||||
}
|
||||
return '';
|
||||
if ( source.startsWith('?') === false ) { return ''; }
|
||||
const steps = source.replace(/(\S)\?/g, '\\1?').split(/\s+/);
|
||||
const url = steps.length === 1
|
||||
? extractParam(elem.href, source)
|
||||
: urlSkip(elem.href, false, steps);
|
||||
if ( url === undefined ) { return; }
|
||||
return url.replace(/ /g, '%20');
|
||||
};
|
||||
const sanitize = ( ) => {
|
||||
let elems = [];
|
||||
|
|
|
|||
Loading…
Reference in a new issue