Validate the Preferences when fetching them from storage
When updating Preferences using the `set` method, the input is carefully validated. However, no validation is (currently) done when a `BasePreferences` instance is created, which probably isn't that great. Hence this patch that simply ignores, to not unnecessarily break loading of the viewer itself, any invalid Preferences.
This commit is contained in:
parent
780cbadcd7
commit
08b05b9fda
@ -60,9 +60,19 @@ class BasePreferences {
|
||||
|
||||
this.prefs = Object.assign(Object.create(null), defaults);
|
||||
return this._readFromStorage(defaults);
|
||||
}).then((prefObj) => {
|
||||
if (prefObj) {
|
||||
this.prefs = prefObj;
|
||||
}).then((prefs) => {
|
||||
if (!prefs) {
|
||||
return;
|
||||
}
|
||||
for (let name in prefs) {
|
||||
const defaultValue = this.defaults[name], prefValue = prefs[name];
|
||||
// Ignore preferences not present in, or whose types don't match,
|
||||
// the default values.
|
||||
if (defaultValue === undefined ||
|
||||
typeof prefValue !== typeof defaultValue) {
|
||||
continue;
|
||||
}
|
||||
this.prefs[name] = prefValue;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user