Skip to content

Commit a1a5f36

Browse files
committed
[mv3] Fix potentially unremovable custom filters
Related issue: uBlockOrigin/uBOL-home#426
1 parent 19a3de9 commit a1a5f36

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

platform/mv3/extension/js/filter-manager.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,14 +178,30 @@ export async function addCustomFilter(hostname, selector) {
178178
/******************************************************************************/
179179

180180
export async function removeCustomFilter(hostname, selector) {
181-
const key = `site.${hostname}`;
181+
const promises = [];
182+
let hn = hostname;
183+
while ( hn !== '' ) {
184+
promises.push(
185+
removeCustomFilterByKey(`site.${hn}`, selector).catch(( ) => false)
186+
);
187+
const pos = hn.indexOf('.');
188+
if ( pos === -1 ) { break; }
189+
hn = hn.slice(pos + 1);
190+
}
191+
const results = await Promise.all(promises);
192+
return results.some(a => a);
193+
}
194+
195+
async function removeCustomFilterByKey(key, selector) {
182196
const selectors = await localRead(key);
183197
if ( selectors === undefined ) { return false; }
184198
const i = selectors.indexOf(selector);
185199
if ( i === -1 ) { return false; }
186200
selectors.splice(i, 1);
187-
await selectors.length !== 0
188-
? localWrite(key, selectors)
189-
: localRemove(key);
201+
if ( selectors.length !== 0 ) {
202+
await localWrite(key, selectors);
203+
} else {
204+
await localRemove(key);
205+
}
190206
return true;
191207
}

0 commit comments

Comments
 (0)