mirror of https://github.com/gorhill/uBlock.git
[mv3] Properly enforce generic cosmetic exception filters
Related issue: - https://github.com/uBlockOrigin/uBOL-issues/issues/58
This commit is contained in:
parent
4a570c151f
commit
4a83b80328
|
@ -396,13 +396,26 @@ function loadAllSourceScriptlets() {
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
async function processGenericCosmeticFilters(assetDetails, bucketsMap) {
|
async function processGenericCosmeticFilters(assetDetails, bucketsMap, exceptionSet) {
|
||||||
if ( bucketsMap === undefined ) { return 0; }
|
if ( bucketsMap === undefined ) { return 0; }
|
||||||
|
if ( exceptionSet ) {
|
||||||
|
for ( const [ hash, selectors ] of bucketsMap ) {
|
||||||
|
let i = selectors.length;
|
||||||
|
while ( i-- ) {
|
||||||
|
const selector = selectors[i];
|
||||||
|
if ( exceptionSet.has(selector) === false ) { continue; }
|
||||||
|
selectors.splice(i, 1);
|
||||||
|
//log(`\tRemoving excepted generic filter ##${selector}`);
|
||||||
|
}
|
||||||
|
if ( selectors.length === 0 ) {
|
||||||
|
bucketsMap.delete(hash);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if ( bucketsMap.size === 0 ) { return 0; }
|
if ( bucketsMap.size === 0 ) { return 0; }
|
||||||
const bucketsList = Array.from(bucketsMap);
|
const bucketsList = Array.from(bucketsMap);
|
||||||
const count = bucketsList.reduce((a, v) => a += v[1].length, 0);
|
const count = bucketsList.reduce((a, v) => a += v[1].length, 0);
|
||||||
if ( count === 0 ) { return 0; }
|
if ( count === 0 ) { return 0; }
|
||||||
|
|
||||||
const selectorLists = bucketsList.map(v => [ v[0], v[1].join(',') ]);
|
const selectorLists = bucketsList.map(v => [ v[0], v[1].join(',') ]);
|
||||||
const originalScriptletMap = await loadAllSourceScriptlets();
|
const originalScriptletMap = await loadAllSourceScriptlets();
|
||||||
|
|
||||||
|
@ -427,8 +440,15 @@ async function processGenericCosmeticFilters(assetDetails, bucketsMap) {
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
async function processGenericHighCosmeticFilters(assetDetails, selectorSet) {
|
async function processGenericHighCosmeticFilters(assetDetails, selectorSet, exceptionSet) {
|
||||||
if ( selectorSet === undefined ) { return 0; }
|
if ( selectorSet === undefined ) { return 0; }
|
||||||
|
if ( exceptionSet ) {
|
||||||
|
for ( const selector of selectorSet ) {
|
||||||
|
if ( exceptionSet.has(selector) === false ) { continue; }
|
||||||
|
selectorSet.delete(selector);
|
||||||
|
//log(`\tRemoving excepted generic filter ##${selector}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
if ( selectorSet.size === 0 ) { return 0; }
|
if ( selectorSet.size === 0 ) { return 0; }
|
||||||
const selectorLists = Array.from(selectorSet).sort().join(',\n');
|
const selectorLists = Array.from(selectorSet).sort().join(',\n');
|
||||||
const originalScriptletMap = await loadAllSourceScriptlets();
|
const originalScriptletMap = await loadAllSourceScriptlets();
|
||||||
|
@ -925,11 +945,13 @@ async function rulesetFromURLs(assetDetails) {
|
||||||
|
|
||||||
const genericCosmeticStats = await processGenericCosmeticFilters(
|
const genericCosmeticStats = await processGenericCosmeticFilters(
|
||||||
assetDetails,
|
assetDetails,
|
||||||
results.genericCosmetic
|
results.genericCosmetic,
|
||||||
|
results.genericCosmeticExceptions
|
||||||
);
|
);
|
||||||
const genericHighCosmeticStats = await processGenericHighCosmeticFilters(
|
const genericHighCosmeticStats = await processGenericHighCosmeticFilters(
|
||||||
assetDetails,
|
assetDetails,
|
||||||
results.genericHighCosmetic
|
results.genericHighCosmetic,
|
||||||
|
results.genericCosmeticExceptions
|
||||||
);
|
);
|
||||||
const specificCosmeticStats = await processCosmeticFilters(
|
const specificCosmeticStats = await processCosmeticFilters(
|
||||||
assetDetails,
|
assetDetails,
|
||||||
|
|
|
@ -150,6 +150,13 @@ function addExtendedToDNR(context, parser) {
|
||||||
const { compiled } = parser.result;
|
const { compiled } = parser.result;
|
||||||
if ( compiled === undefined ) { return; }
|
if ( compiled === undefined ) { return; }
|
||||||
if ( compiled.length <= 1 ) { return; }
|
if ( compiled.length <= 1 ) { return; }
|
||||||
|
if ( parser.isException() ) {
|
||||||
|
if ( context.genericCosmeticExceptions === undefined ) {
|
||||||
|
context.genericCosmeticExceptions = new Set();
|
||||||
|
}
|
||||||
|
context.genericCosmeticExceptions.add(compiled);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if ( compiled.charCodeAt(0) === 0x7B /* '{' */ ) { return; }
|
if ( compiled.charCodeAt(0) === 0x7B /* '{' */ ) { return; }
|
||||||
const key = keyFromSelector(compiled);
|
const key = keyFromSelector(compiled);
|
||||||
if ( key === undefined ) {
|
if ( key === undefined ) {
|
||||||
|
@ -298,6 +305,7 @@ async function dnrRulesetFromRawLists(lists, options = {}) {
|
||||||
network: staticNetFilteringEngine.dnrFromCompiled('end', context),
|
network: staticNetFilteringEngine.dnrFromCompiled('end', context),
|
||||||
genericCosmetic: context.genericCosmeticFilters,
|
genericCosmetic: context.genericCosmeticFilters,
|
||||||
genericHighCosmetic: context.genericHighCosmeticFilters,
|
genericHighCosmetic: context.genericHighCosmeticFilters,
|
||||||
|
genericCosmeticExceptions: context.genericCosmeticExceptions,
|
||||||
specificCosmetic: context.specificCosmeticFilters,
|
specificCosmetic: context.specificCosmeticFilters,
|
||||||
scriptlet: context.scriptletFilters,
|
scriptlet: context.scriptletFilters,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue