You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-07-16 00:14:34 +02:00
Desktop: Fixes #5086: Prevent app from crashing when loading a setting value that has been removed
This commit is contained in:
@ -30,6 +30,24 @@ describe('models_Setting', function() {
|
||||
expect('username' in output).toBe(false);
|
||||
}));
|
||||
|
||||
it('should not fail when trying to load a key that no longer exist from the setting file', (async () => {
|
||||
// To handle the case where a setting value exists in the database but
|
||||
// the metadata has been removed in a new Joplin version.
|
||||
// https://github.com/laurent22/joplin/issues/5086
|
||||
|
||||
Setting.setValue('sync.target', 9); // Saved to file
|
||||
await Setting.saveAll();
|
||||
|
||||
const settingValues = await Setting.fileHandler.load();
|
||||
settingValues['itsgone'] = 'myvalue';
|
||||
await Setting.fileHandler.save(settingValues);
|
||||
|
||||
await Setting.reset();
|
||||
|
||||
await expectNotThrow(async () => Setting.load());
|
||||
await expectThrow(async () => Setting.value('itsgone'));
|
||||
}));
|
||||
|
||||
it('should allow registering new settings dynamically', (async () => {
|
||||
await expectThrow(async () => Setting.setValue('myCustom', '123'));
|
||||
|
||||
|
@ -232,7 +232,7 @@ class Setting extends BaseModel {
|
||||
return `${this.value('profileDir')}/settings.json`;
|
||||
}
|
||||
|
||||
private static get fileHandler(): FileHandler {
|
||||
public static get fileHandler(): FileHandler {
|
||||
if (!this.fileHandler_) {
|
||||
this.fileHandler_ = new FileHandler(this.settingFilePath);
|
||||
}
|
||||
@ -1405,7 +1405,7 @@ class Setting extends BaseModel {
|
||||
for (const k of Object.keys(fromFile)) {
|
||||
itemsFromFile.push({
|
||||
key: k,
|
||||
value: this.filterValue(k, this.formatValue(k, fromFile[k])),
|
||||
value: fromFile[k],
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user