Add some validation to options loading
This commit is contained in:
parent
1c767711bb
commit
ec110fa1b7
@ -323,10 +323,23 @@ function optionsVersion(options) {
|
|||||||
|
|
||||||
function optionsLoad() {
|
function optionsLoad() {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
chrome.storage.local.get(null, store => resolve(store.options));
|
chrome.storage.local.get(['options'], store => {
|
||||||
|
const error = chrome.runtime.lastError;
|
||||||
|
if (error) {
|
||||||
|
reject(error);
|
||||||
|
} else {
|
||||||
|
resolve(store.options);
|
||||||
|
}
|
||||||
|
});
|
||||||
}).then(optionsStr => {
|
}).then(optionsStr => {
|
||||||
return optionsStr ? JSON.parse(optionsStr) : {};
|
if (typeof optionsStr === 'string') {
|
||||||
}).catch(error => {
|
const options = JSON.parse(optionsStr);
|
||||||
|
if (typeof options === 'object' && options !== null && !Array.isArray(options)) {
|
||||||
|
return options;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {};
|
||||||
|
}).catch(() => {
|
||||||
return {};
|
return {};
|
||||||
}).then(options => {
|
}).then(options => {
|
||||||
return optionsVersion(options);
|
return optionsVersion(options);
|
||||||
@ -334,7 +347,7 @@ function optionsLoad() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function optionsSave(options) {
|
function optionsSave(options) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve) => {
|
||||||
chrome.storage.local.set({options: JSON.stringify(options)}, resolve);
|
chrome.storage.local.set({options: JSON.stringify(options)}, resolve);
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
apiOptionsSet(options);
|
apiOptionsSet(options);
|
||||||
|
Loading…
Reference in New Issue
Block a user