mirror of https://github.com/gorhill/uBlock.git
[mv3] Fix flaw breaking scriptlets injection in optimal/basic mode
Not all matching scriptlets were injected on a given site in Optimal or Complete mode when default mode was set to Basic or less. A high profile manifestation of this bug was that Youtube ads were not being blocked when using Optimal on Youtube while default mode was Basic.
This commit is contained in:
parent
8ae33afb76
commit
6355a17187
|
@ -450,8 +450,8 @@ function registerScriptlet(context, scriptletDetails) {
|
||||||
targetHostnames = permissionGrantedHostnames;
|
targetHostnames = permissionGrantedHostnames;
|
||||||
} else {
|
} else {
|
||||||
targetHostnames = ut.intersectHostnameIters(
|
targetHostnames = ut.intersectHostnameIters(
|
||||||
permissionGrantedHostnames,
|
scriptletHostnames,
|
||||||
scriptletHostnames
|
permissionGrantedHostnames
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,6 +47,13 @@ const isDescendantHostname = (hna, hnb) => {
|
||||||
return hna.charCodeAt(hna.length - hnb.length - 1) === 0x2E /* '.' */;
|
return hna.charCodeAt(hna.length - hnb.length - 1) === 0x2E /* '.' */;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether a hostname is part of a collection, or is descendant of an
|
||||||
|
* item in the collection.
|
||||||
|
* @param hna - the hostname representing the needle.
|
||||||
|
* @param iterb - an iterable representing the haystack of hostnames.
|
||||||
|
*/
|
||||||
|
|
||||||
const isDescendantHostnameOfIter = (hna, iterb) => {
|
const isDescendantHostnameOfIter = (hna, iterb) => {
|
||||||
const setb = iterb instanceof Set ? iterb : new Set(iterb);
|
const setb = iterb instanceof Set ? iterb : new Set(iterb);
|
||||||
if ( setb.has('all-urls') || setb.has('*') ) { return true; }
|
if ( setb.has('all-urls') || setb.has('*') ) { return true; }
|
||||||
|
@ -60,6 +67,13 @@ const isDescendantHostnameOfIter = (hna, iterb) => {
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns all hostnames in the first collection which are equal or descendant
|
||||||
|
* of hostnames in the second collection.
|
||||||
|
* @param itera - an iterable which hostnames must be filtered out.
|
||||||
|
* @param iterb - an iterable which hostnames must be matched.
|
||||||
|
*/
|
||||||
|
|
||||||
const intersectHostnameIters = (itera, iterb) => {
|
const intersectHostnameIters = (itera, iterb) => {
|
||||||
const setb = iterb instanceof Set ? iterb : new Set(iterb);
|
const setb = iterb instanceof Set ? iterb : new Set(iterb);
|
||||||
if ( setb.has('all-urls') || setb.has('*') ) { return Array.from(itera); }
|
if ( setb.has('all-urls') || setb.has('*') ) { return Array.from(itera); }
|
||||||
|
|
Loading…
Reference in New Issue