Skip to content

Commit 4150c17

Browse files
committed
Add concept of "really bad list" to badlists infrastructure
This commit adds concept of "really bad list" to the badlists infrastructure. Really bad lists won't be fetched from a remote server, while plain bad list will be fetched but won't be compiled. A really bad list is denoted by the `nofetch` token following the URL. Really bad lists can cause more serious issues such as causing undue launch delays because the remote server where a really bad list is hosted fails to respond properly and times out. Such an example of really bad list is hpHosts which original server no longer exist.
1 parent 3d048c9 commit 4150c17

File tree

2 files changed

+27
-16
lines changed

2 files changed

+27
-16
lines changed

src/js/background.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ const µBlock = (( ) => { // jshint ignore:line
171171

172172
selectedFilterLists: [],
173173
availableFilterLists: {},
174-
badLists: new Set(),
174+
badLists: new Map(),
175175

176176
// https://github.com/uBlockOrigin/uBlock-issues/issues/974
177177
// This can be used to defer filtering decision-making.

src/js/storage.js

+26-15
Original file line numberDiff line numberDiff line change
@@ -481,15 +481,6 @@ self.addEventListener('hiddenSettingsChanged', ( ) => {
481481
let oldAvailableLists = {},
482482
newAvailableLists = {};
483483

484-
if ( this.badLists.size === 0 ) {
485-
const details = await this.assets.get('ublock-badlists');
486-
this.badLists = new Set(
487-
details.content.split(/\s*[\n\r]+\s*/).filter(a => {
488-
return a !== '' && a.startsWith('#') === false;
489-
})
490-
);
491-
}
492-
493484
// User filter list.
494485
newAvailableLists[this.userFiltersPath] = {
495486
group: 'user',
@@ -538,12 +529,24 @@ self.addEventListener('hiddenSettingsChanged', ( ) => {
538529
this.saveSelectedFilterLists([ listURL ], true);
539530
};
540531

541-
// Load previously saved available lists -- these contains data
542-
// computed at run-time, we will reuse this data if possible.
543-
const [ bin, entries ] = await Promise.all([
532+
const promises = [
544533
vAPI.storage.get('availableFilterLists'),
545534
this.assets.metadata(),
546-
]);
535+
this.badLists.size === 0 ? this.assets.get('ublock-badlists') : false,
536+
];
537+
538+
// Load previously saved available lists -- these contains data
539+
// computed at run-time, we will reuse this data if possible.
540+
const [ bin, entries, badlists ] = await Promise.all(promises);
541+
542+
if ( badlists instanceof Object ) {
543+
for ( const line of badlists.content.split(/\s*[\n\r]+\s*/) ) {
544+
if ( line === '' || line.startsWith('#') ) { continue; }
545+
const fields = line.split(/\s+/);
546+
const remove = fields.length === 2 && fields[1] === 'nofetch';
547+
this.badLists.set(fields[0], remove);
548+
}
549+
}
547550

548551
oldAvailableLists = bin && bin.availableFilterLists || {};
549552

@@ -725,6 +728,11 @@ self.addEventListener('hiddenSettingsChanged', ( ) => {
725728
}
726729
}
727730

731+
// Skip downloading really bad lists.
732+
if ( this.badLists.get(assetKey) ) {
733+
return { assetKey, content: '' };
734+
}
735+
728736
const rawDetails = await this.assets.get(assetKey);
729737
// Compiling an empty string results in an empty string.
730738
if ( rawDetails.content === '' ) {
@@ -1331,11 +1339,14 @@ self.addEventListener('hiddenSettingsChanged', ( ) => {
13311339

13321340
µBlock.assetObserver = function(topic, details) {
13331341
// Do not update filter list if not in use.
1342+
// Also, ignore really bad lists, i.e. those which should not even be
1343+
// fetched from a remote server.
13341344
if ( topic === 'before-asset-updated' ) {
13351345
if ( details.type === 'filters' ) {
13361346
if (
13371347
this.availableFilterLists.hasOwnProperty(details.assetKey) === false ||
1338-
this.selectedFilterLists.indexOf(details.assetKey) === -1
1348+
this.selectedFilterLists.indexOf(details.assetKey) === -1 ||
1349+
this.badLists.get(details.assetKey)
13391350
) {
13401351
return;
13411352
}
@@ -1374,7 +1385,7 @@ self.addEventListener('hiddenSettingsChanged', ( ) => {
13741385
this.compilePublicSuffixList(details.content);
13751386
}
13761387
} else if ( details.assetKey === 'ublock-badlists' ) {
1377-
this.badLists = new Set();
1388+
this.badLists = new Map();
13781389
}
13791390
vAPI.messaging.broadcast({
13801391
what: 'assetUpdated',

0 commit comments

Comments
 (0)