mirror of
https://github.com/gorhill/uBlock.git
synced 2024-10-06 09:37:12 +02:00
Don't match network filter-derived regexes against non-network URIs
Context: element picker Related issue: https://github.com/uBlockOrigin/uBlock-issues/issues/3142
This commit is contained in:
parent
f7e00e4223
commit
2262a129ec
@ -619,6 +619,21 @@ const filterToDOMInterface = (( ) => {
|
|||||||
const reCaret = '(?:[^%.0-9a-z_-]|$)';
|
const reCaret = '(?:[^%.0-9a-z_-]|$)';
|
||||||
const rePseudoElements = /:(?::?after|:?before|:[a-z-]+)$/;
|
const rePseudoElements = /:(?::?after|:?before|:[a-z-]+)$/;
|
||||||
|
|
||||||
|
const matchElemToRegex = (elem, re) => {
|
||||||
|
const srcProp = netFilter1stSources[elem.localName];
|
||||||
|
let src = elem[srcProp];
|
||||||
|
if ( src instanceof SVGAnimatedString ) {
|
||||||
|
src = src.baseVal;
|
||||||
|
}
|
||||||
|
if ( typeof src === 'string' && /^https?:\/\//.test(src) ) {
|
||||||
|
if ( re.test(src) ) { return srcProp; }
|
||||||
|
}
|
||||||
|
src = elem.currentSrc;
|
||||||
|
if ( typeof src === 'string' && /^https?:\/\//.test(src) ) {
|
||||||
|
if ( re.test(src) ) { return srcProp; }
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// Net filters: we need to lookup manually -- translating into a foolproof
|
// Net filters: we need to lookup manually -- translating into a foolproof
|
||||||
// CSS selector is just not possible.
|
// CSS selector is just not possible.
|
||||||
//
|
//
|
||||||
@ -672,21 +687,15 @@ const filterToDOMInterface = (( ) => {
|
|||||||
// Lookup by tag names.
|
// Lookup by tag names.
|
||||||
// https://github.com/uBlockOrigin/uBlock-issues/issues/2260
|
// https://github.com/uBlockOrigin/uBlock-issues/issues/2260
|
||||||
// Maybe get to the actual URL indirectly.
|
// Maybe get to the actual URL indirectly.
|
||||||
|
//
|
||||||
|
// https://github.com/uBlockOrigin/uBlock-issues/issues/3142
|
||||||
|
// Don't try to match against non-network URIs.
|
||||||
const elems = document.querySelectorAll(
|
const elems = document.querySelectorAll(
|
||||||
Object.keys(netFilter1stSources).join()
|
Object.keys(netFilter1stSources).join()
|
||||||
);
|
);
|
||||||
for ( const elem of elems ) {
|
for ( const elem of elems ) {
|
||||||
const srcProp = netFilter1stSources[elem.localName];
|
const srcProp = matchElemToRegex(elem, reFilter);
|
||||||
let src = elem[srcProp];
|
if ( srcProp === undefined ) { continue; }
|
||||||
if ( src instanceof SVGAnimatedString ) {
|
|
||||||
src = src.baseVal;
|
|
||||||
}
|
|
||||||
if (
|
|
||||||
typeof src === 'string' &&
|
|
||||||
reFilter.test(src) ||
|
|
||||||
typeof elem.currentSrc === 'string' &&
|
|
||||||
reFilter.test(elem.currentSrc)
|
|
||||||
) {
|
|
||||||
out.push({
|
out.push({
|
||||||
elem,
|
elem,
|
||||||
src: srcProp,
|
src: srcProp,
|
||||||
@ -694,7 +703,6 @@ const filterToDOMInterface = (( ) => {
|
|||||||
style: vAPI.hideStyle,
|
style: vAPI.hideStyle,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Find matching background image in current set of candidate elements.
|
// Find matching background image in current set of candidate elements.
|
||||||
for ( const elem of candidateElements ) {
|
for ( const elem of candidateElements ) {
|
||||||
|
Loading…
Reference in New Issue
Block a user