Prevent all strings from being parsed as JSON.

This commit is contained in:
Ajay Ramachandran
2020-02-08 20:15:49 -05:00
parent be3a4a4e91
commit 94af8ab301

View File

@@ -84,7 +84,6 @@ class SBMap<T, U> extends Map {
} }
} }
var Config: SBObject = { var Config: SBObject = {
/** /**
* Callback function when an option is updated * Callback function when an option is updated
@@ -138,11 +137,11 @@ function encodeStoredItem(data) {
* @param {*} data * @param {*} data
*/ */
function decodeStoredItem(id: string, data) { function decodeStoredItem(id: string, data) {
if(!Config.defaults[id]) return data; if (!Config.defaults[id]) return data;
if(Config.defaults[id] instanceof SBMap) { if (Config.defaults[id] instanceof SBMap) {
try { try {
if(!Array.isArray(data)) return data; if (!Array.isArray(data)) return data;
return new SBMap(id, data); return new SBMap(id, data);
} catch(e) { } catch(e) {
console.error("Failed to parse SBMap: "+ id); console.error("Failed to parse SBMap: "+ id);
@@ -151,10 +150,14 @@ function decodeStoredItem(id: string, data) {
// This is the old format for SBMap (a JSON string) // This is the old format for SBMap (a JSON string)
if (typeof data === "string") { if (typeof data === "string") {
let str = JSON.parse(data); try {
let str = JSON.parse(data);
if(Array.isArray(data)) { if (Array.isArray(data)) {
return new SBMap(id, str) return new SBMap(id, str);
}
} catch(e) {
// Continue normally (out of this if statement)
} }
} }