[mv3] Properly enforce generic cosmetic exception filters

Related issue:
- https://github.com/uBlockOrigin/uBOL-issues/issues/58
This commit is contained in:
Raymond Hill 2023-07-11 14:38:35 -04:00
parent 4a570c151f
commit 4a83b80328
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
2 changed files with 35 additions and 5 deletions

View File

@ -396,13 +396,26 @@ function loadAllSourceScriptlets() {
/******************************************************************************/
async function processGenericCosmeticFilters(assetDetails, bucketsMap) {
async function processGenericCosmeticFilters(assetDetails, bucketsMap, exceptionSet) {
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; }
const bucketsList = Array.from(bucketsMap);
const count = bucketsList.reduce((a, v) => a += v[1].length, 0);
if ( count === 0 ) { return 0; }
const selectorLists = bucketsList.map(v => [ v[0], v[1].join(',') ]);
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 ( 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; }
const selectorLists = Array.from(selectorSet).sort().join(',\n');
const originalScriptletMap = await loadAllSourceScriptlets();
@ -925,11 +945,13 @@ async function rulesetFromURLs(assetDetails) {
const genericCosmeticStats = await processGenericCosmeticFilters(
assetDetails,
results.genericCosmetic
results.genericCosmetic,
results.genericCosmeticExceptions
);
const genericHighCosmeticStats = await processGenericHighCosmeticFilters(
assetDetails,
results.genericHighCosmetic
results.genericHighCosmetic,
results.genericCosmeticExceptions
);
const specificCosmeticStats = await processCosmeticFilters(
assetDetails,

View File

@ -150,6 +150,13 @@ function addExtendedToDNR(context, parser) {
const { compiled } = parser.result;
if ( compiled === undefined ) { 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; }
const key = keyFromSelector(compiled);
if ( key === undefined ) {
@ -298,6 +305,7 @@ async function dnrRulesetFromRawLists(lists, options = {}) {
network: staticNetFilteringEngine.dnrFromCompiled('end', context),
genericCosmetic: context.genericCosmeticFilters,
genericHighCosmetic: context.genericHighCosmeticFilters,
genericCosmeticExceptions: context.genericCosmeticExceptions,
specificCosmetic: context.specificCosmeticFilters,
scriptlet: context.scriptletFilters,
};