mirror of
https://github.com/gorhill/uBlock.git
synced 2024-10-06 09:37:12 +02:00
Fix broken forward compatibility re. imported lists
Related issue: - https://github.com/uBlockOrigin/uBlock-issues/issues/1480 Forward compatiblity was broken due to `externalLists` being converted into an Array from a string, i.e. downgrading to uBO 1.32.4 was completely breaking uBO. This commit restores `externalLists` as a string which is what older versions of uBO expect. A new property `importedLists` has been created to hold the imported lists as an array, while `externalLists` will be kept around for a while until it is completely removed in some future.
This commit is contained in:
parent
93ed308741
commit
3bb73065e3
@ -92,10 +92,11 @@ const µBlock = (( ) => { // jshint ignore:line
|
|||||||
colorBlindFriendly: false,
|
colorBlindFriendly: false,
|
||||||
contextMenuEnabled: true,
|
contextMenuEnabled: true,
|
||||||
dynamicFilteringEnabled: false,
|
dynamicFilteringEnabled: false,
|
||||||
externalLists: [],
|
externalLists: '',
|
||||||
firewallPaneMinimized: true,
|
firewallPaneMinimized: true,
|
||||||
hyperlinkAuditingDisabled: true,
|
hyperlinkAuditingDisabled: true,
|
||||||
ignoreGenericCosmeticFilters: vAPI.webextFlavor.soup.has('mobile'),
|
ignoreGenericCosmeticFilters: vAPI.webextFlavor.soup.has('mobile'),
|
||||||
|
importedLists: [],
|
||||||
largeMediaSize: 50,
|
largeMediaSize: 50,
|
||||||
parseAllABPHideFilters: true,
|
parseAllABPHideFilters: true,
|
||||||
popupPanelSections: 0b111,
|
popupPanelSections: 0b111,
|
||||||
|
@ -949,9 +949,9 @@ const restoreUserData = async function(request) {
|
|||||||
userData.hostnameSwitchesString += '\nno-csp-reports: * true';
|
userData.hostnameSwitchesString += '\nno-csp-reports: * true';
|
||||||
}
|
}
|
||||||
|
|
||||||
// List of external lists is meant to be an array.
|
// List of external lists is meant to be a string.
|
||||||
if ( typeof userData.externalLists === 'string' ) {
|
if ( Array.isArray(userData.externalLists) ) {
|
||||||
userData.externalLists = userData.externalLists.trim().split(/[\n\r]+/);
|
userData.externalLists = userData.externalLists.join('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://github.com/chrisaljoudi/uBlock/issues/1102
|
// https://github.com/chrisaljoudi/uBlock/issues/1102
|
||||||
|
@ -160,9 +160,18 @@ const onNetWhitelistReady = function(netWhitelistRaw, adminExtra) {
|
|||||||
// User settings are in memory
|
// User settings are in memory
|
||||||
|
|
||||||
const onUserSettingsReady = function(fetched) {
|
const onUserSettingsReady = function(fetched) {
|
||||||
// List of external lists is meant to be an array
|
// `externalLists` will be deprecated in some future, it is kept around
|
||||||
if ( typeof fetched.externalLists === 'string' ) {
|
// for forward compatibility purpose, and should reflect the content of
|
||||||
fetched.externalLists =
|
// `importedLists`.
|
||||||
|
if ( Array.isArray(fetched.externalLists) ) {
|
||||||
|
fetched.externalLists = fetched.externalLists.join('\n');
|
||||||
|
vAPI.storage.set({ externalLists: fetched.externalLists });
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
fetched.importedLists.length === 0 &&
|
||||||
|
fetched.externalLists !== ''
|
||||||
|
) {
|
||||||
|
fetched.importedLists =
|
||||||
fetched.externalLists.trim().split(/[\n\r]+/);
|
fetched.externalLists.trim().split(/[\n\r]+/);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,10 +116,17 @@
|
|||||||
this.userSettings,
|
this.userSettings,
|
||||||
this.userSettingsDefault
|
this.userSettingsDefault
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// `externalLists` will be deprecated in some future, it is kept around
|
||||||
|
// for forward compatibility purpose, and should reflect the content of
|
||||||
|
// `importedLists`.
|
||||||
|
this.userSettings.externalLists =
|
||||||
|
this.userSettings.importedLists.join('\n');
|
||||||
|
|
||||||
const toRemove = [];
|
const toRemove = [];
|
||||||
for ( const key in this.userSettings ) {
|
for ( const key in this.userSettings ) {
|
||||||
if ( this.userSettings.hasOwnProperty(key) === false ) { continue; }
|
if ( this.userSettings.hasOwnProperty(key) === false ) { continue; }
|
||||||
if ( toSave.hasOwnProperty(key) === false ) { continue; }
|
if ( toSave.hasOwnProperty(key) ) { continue; }
|
||||||
toRemove.push(key);
|
toRemove.push(key);
|
||||||
}
|
}
|
||||||
if ( toRemove.length !== 0 ) {
|
if ( toRemove.length !== 0 ) {
|
||||||
@ -368,7 +375,7 @@ self.addEventListener('hiddenSettingsChanged', ( ) => {
|
|||||||
|
|
||||||
µBlock.applyFilterListSelection = function(details) {
|
µBlock.applyFilterListSelection = function(details) {
|
||||||
let selectedListKeySet = new Set(this.selectedFilterLists);
|
let selectedListKeySet = new Set(this.selectedFilterLists);
|
||||||
let externalLists = this.userSettings.externalLists.slice();
|
let importedLists = this.userSettings.importedLists.slice();
|
||||||
|
|
||||||
// Filter lists to select
|
// Filter lists to select
|
||||||
if ( Array.isArray(details.toSelect) ) {
|
if ( Array.isArray(details.toSelect) ) {
|
||||||
@ -386,9 +393,9 @@ self.addEventListener('hiddenSettingsChanged', ( ) => {
|
|||||||
for ( let i = 0, n = details.toRemove.length; i < n; i++ ) {
|
for ( let i = 0, n = details.toRemove.length; i < n; i++ ) {
|
||||||
const assetKey = details.toRemove[i];
|
const assetKey = details.toRemove[i];
|
||||||
selectedListKeySet.delete(assetKey);
|
selectedListKeySet.delete(assetKey);
|
||||||
const pos = externalLists.indexOf(assetKey);
|
const pos = importedLists.indexOf(assetKey);
|
||||||
if ( pos !== -1 ) {
|
if ( pos !== -1 ) {
|
||||||
externalLists.splice(pos, 1);
|
importedLists.splice(pos, 1);
|
||||||
}
|
}
|
||||||
this.removeFilterList(assetKey);
|
this.removeFilterList(assetKey);
|
||||||
}
|
}
|
||||||
@ -418,7 +425,7 @@ self.addEventListener('hiddenSettingsChanged', ( ) => {
|
|||||||
}
|
}
|
||||||
return url;
|
return url;
|
||||||
};
|
};
|
||||||
const importedSet = new Set(this.listKeysFromCustomFilterLists(externalLists));
|
const importedSet = new Set(this.listKeysFromCustomFilterLists(importedLists));
|
||||||
const toImportSet = new Set(this.listKeysFromCustomFilterLists(details.toImport));
|
const toImportSet = new Set(this.listKeysFromCustomFilterLists(details.toImport));
|
||||||
for ( const urlKey of toImportSet ) {
|
for ( const urlKey of toImportSet ) {
|
||||||
if ( importedSet.has(urlKey) ) {
|
if ( importedSet.has(urlKey) ) {
|
||||||
@ -431,12 +438,12 @@ self.addEventListener('hiddenSettingsChanged', ( ) => {
|
|||||||
}
|
}
|
||||||
selectedListKeySet.add(assetKey);
|
selectedListKeySet.add(assetKey);
|
||||||
}
|
}
|
||||||
externalLists = Array.from(importedSet).sort();
|
importedLists = Array.from(importedSet).sort();
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = Array.from(selectedListKeySet);
|
const result = Array.from(selectedListKeySet);
|
||||||
if ( externalLists.join() !== this.userSettings.externalLists.join() ) {
|
if ( importedLists.join() !== this.userSettings.importedLists.join() ) {
|
||||||
this.userSettings.externalLists = externalLists;
|
this.userSettings.importedLists = importedLists;
|
||||||
this.saveUserSettings();
|
this.saveUserSettings();
|
||||||
}
|
}
|
||||||
this.saveSelectedFilterLists(result);
|
this.saveSelectedFilterLists(result);
|
||||||
@ -597,7 +604,7 @@ self.addEventListener('hiddenSettingsChanged', ( ) => {
|
|||||||
|
|
||||||
// Custom filter lists.
|
// Custom filter lists.
|
||||||
const importedListKeys = this.listKeysFromCustomFilterLists(
|
const importedListKeys = this.listKeysFromCustomFilterLists(
|
||||||
this.userSettings.externalLists
|
this.userSettings.importedLists
|
||||||
);
|
);
|
||||||
for ( const listKey of importedListKeys ) {
|
for ( const listKey of importedListKeys ) {
|
||||||
const entry = {
|
const entry = {
|
||||||
@ -631,7 +638,7 @@ self.addEventListener('hiddenSettingsChanged', ( ) => {
|
|||||||
newAvailableLists[listURL] = newEntry;
|
newAvailableLists[listURL] = newEntry;
|
||||||
this.assets.registerAssetSource(listURL, newEntry);
|
this.assets.registerAssetSource(listURL, newEntry);
|
||||||
importedListKeys.push(listURL);
|
importedListKeys.push(listURL);
|
||||||
this.userSettings.externalLists.push(listURL.trim());
|
this.userSettings.importedLists.push(listURL.trim());
|
||||||
this.saveUserSettings();
|
this.saveUserSettings();
|
||||||
this.saveSelectedFilterLists([ listURL ], true);
|
this.saveSelectedFilterLists([ listURL ], true);
|
||||||
};
|
};
|
||||||
@ -1351,11 +1358,6 @@ self.addEventListener('hiddenSettingsChanged', ( ) => {
|
|||||||
if ( typeof data.userSettings === 'object' ) {
|
if ( typeof data.userSettings === 'object' ) {
|
||||||
const µbus = this.userSettings;
|
const µbus = this.userSettings;
|
||||||
const adminus = data.userSettings;
|
const adminus = data.userSettings;
|
||||||
// List of external lists is meant to be an array.
|
|
||||||
if ( typeof adminus.externalLists === 'string' ) {
|
|
||||||
adminus.externalLists =
|
|
||||||
adminus.externalLists.trim().split(/[\n\r]+/);
|
|
||||||
}
|
|
||||||
for ( const name in µbus ) {
|
for ( const name in µbus ) {
|
||||||
if ( µbus.hasOwnProperty(name) === false ) { continue; }
|
if ( µbus.hasOwnProperty(name) === false ) { continue; }
|
||||||
if ( adminus.hasOwnProperty(name) === false ) { continue; }
|
if ( adminus.hasOwnProperty(name) === false ) { continue; }
|
||||||
@ -1371,13 +1373,14 @@ self.addEventListener('hiddenSettingsChanged', ( ) => {
|
|||||||
Array.isArray(toOverwrite.filterLists) &&
|
Array.isArray(toOverwrite.filterLists) &&
|
||||||
toOverwrite.filterLists.length !== 0
|
toOverwrite.filterLists.length !== 0
|
||||||
) {
|
) {
|
||||||
const externalLists = [];
|
const importedLists = [];
|
||||||
for ( const list of toOverwrite.filterLists ) {
|
for ( const list of toOverwrite.filterLists ) {
|
||||||
if ( /^[a-z-]+:\/\//.test(list) === false ) { continue; }
|
if ( /^[a-z-]+:\/\//.test(list) === false ) { continue; }
|
||||||
externalLists.push(list);
|
importedLists.push(list);
|
||||||
}
|
}
|
||||||
if ( externalLists.length !== 0 ) {
|
if ( importedLists.length !== 0 ) {
|
||||||
bin.externalLists = externalLists;
|
bin.importedLists = importedLists;
|
||||||
|
bin.externalLists = importedLists.join('\n');
|
||||||
}
|
}
|
||||||
bin.selectedFilterLists = toOverwrite.filterLists;
|
bin.selectedFilterLists = toOverwrite.filterLists;
|
||||||
binNotEmpty = true;
|
binNotEmpty = true;
|
||||||
|
@ -687,6 +687,8 @@
|
|||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
|
// TODO: properly compare arrays
|
||||||
|
|
||||||
µBlock.getModifiedSettings = function(edit, orig = {}) {
|
µBlock.getModifiedSettings = function(edit, orig = {}) {
|
||||||
const out = {};
|
const out = {};
|
||||||
for ( const prop in edit ) {
|
for ( const prop in edit ) {
|
||||||
|
Loading…
Reference in New Issue
Block a user