Fix reverse lookup of generic cosmetic filters

Related feedback:
- 26594fb902 (commitcomment-92413254)
This commit is contained in:
Raymond Hill 2022-12-08 10:07:58 -05:00
parent 96e75770c2
commit f1b19d5115
No known key found for this signature in database
GPG key ID: 25E1490B761470C2
2 changed files with 4 additions and 28 deletions

View file

@ -737,22 +737,17 @@ FilterContainer.prototype.retrieveGenericSelectors = function(request) {
const selectorsSet = new Set();
const hashes = [];
const safeOnly = request.safeOnly === true;
for ( const hash of request.hashes ) {
const bucket = this.lowlyGeneric.get(hash);
if ( bucket === undefined ) { continue; }
for ( const selector of bucket.split(',\n') ) {
if ( safeOnly && selector === keyFromSelector(selector) ) { continue; }
selectorsSet.add(selector);
}
hashes.push(hash);
}
if ( request.safeOnly ) {
for ( const selector of selectorsSet ) {
if ( selector !== keyFromSelector(selector) ) { continue; }
selectorsSet.delete(selector);
}
}
// Apply exceptions: it is the responsibility of the caller to provide
// the exceptions to be applied.
const excepted = [];

View file

@ -183,33 +183,14 @@ const fromExtendedFilter = function(details) {
const filterType = fargs[0];
// https://github.com/gorhill/uBlock/issues/2763
if (
filterType >= 0 &&
filterType <= 5 &&
details.ignoreGeneric
) {
continue;
}
if ( filterType === 0 && details.ignoreGeneric ) { continue; }
// Do not confuse cosmetic filters with HTML ones.
if ( (filterType === 64) !== isHtmlFilter ) { continue; }
switch ( filterType ) {
// Lowly generic cosmetic filters
case 0: // simple id-based
if ( exception ) { break; }
if ( fargs[1] !== selector.slice(1) ) { break; }
if ( selector.charAt(0) !== '#' ) { break; }
found = prefix + selector;
break;
case 2: // simple class-based
if ( exception ) { break; }
if ( fargs[1] !== selector.slice(1) ) { break; }
if ( selector.charAt(0) !== '.' ) { break; }
found = prefix + selector;
break;
case 1: // complex id-based
case 3: // complex class-based
case 0:
if ( exception ) { break; }
if ( fargs[2] !== selector ) { break; }
found = prefix + selector;