[mv3] Fix regression with highly generic cosmetic filters CSS files

Regression from:
56ba93700c

Related feedback:
https://old.reddit.com/r/uBlockOrigin/comments/1mi8fd6/ublock_origin_lite_for_ios/n725s6l/
This commit is contained in:
Raymond Hill 2025-08-05 13:25:14 -04:00
parent e390822930
commit 1e0c64076f
No known key found for this signature in database
GPG key ID: 25E1490B761470C2

View file

@ -221,42 +221,48 @@ function addExtendedToDNR(context, parser) {
});
return;
}
let details = context.specificCosmeticFilters.get(compiled);
let isGeneric = true;
const matches = [];
const excludeMatches = [];
for ( const { hn, not, bad } of parser.getExtFilterDomainIterator() ) {
if ( bad ) { continue; }
if ( not && exception ) { continue; }
isGeneric = false;
// TODO: Support regex- and path-based entries
if ( isRegexOrPath(hn) ) { continue; }
if ( details === undefined ) {
context.specificCosmeticFilters.set(compiled, details = {});
if ( not || exception ) {
excludeMatches.push(hn);
} else if ( hn !== '*' ) {
matches.push(hn);
}
if ( compiled.startsWith('{') === false ) {
details.key = keyFromSelector(compiled);
}
if ( exception || not ) {
if ( details.excludeMatches === undefined ) {
details.excludeMatches = [];
}
details.excludeMatches.push(hn);
continue;
}
// This should not happen
if ( matches.length === 0 && excludeMatches.length === 0 ) { return; }
// Only negated hostnames => generic cosmetic filter
if ( exception === false && matches.length === 0 && excludeMatches.length !== 0 ) {
addGenericCosmeticFilter(context, compiled, false);
}
const key = compiled.startsWith('{') === false && keyFromSelector(compiled);
let details = context.specificCosmeticFilters.get(compiled);
if ( details === undefined ) {
context.specificCosmeticFilters.set(compiled, details = {});
if ( key ) {
details.key = key;
}
}
if ( matches.length ) {
if ( details.matches === undefined ) {
details.matches = [];
}
if ( details.matches.includes('*') ) { continue; }
if ( hn === '*' ) {
if ( matches.includes('*') ) {
details.matches = [ '*' ];
continue;
} else if ( details.matches.includes('*') === false ) {
details.matches.push(...matches);
}
details.matches.push(hn);
}
if ( details === undefined ) { return; }
if ( exception ) { return; }
if ( compiled.startsWith('{') ) { return; }
if ( isGeneric ) {
addGenericCosmeticFilter(context, compiled, false);
if ( excludeMatches.length ) {
if ( details.excludeMatches === undefined ) {
details.excludeMatches = [];
}
details.excludeMatches.push(...excludeMatches);
}
}