mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-10 13:37:04 +03:00
Prevent all strings from being parsed as JSON.
This commit is contained in:
@@ -84,7 +84,6 @@ class SBMap<T, U> extends Map {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var Config: SBObject = {
|
||||
/**
|
||||
* Callback function when an option is updated
|
||||
@@ -138,11 +137,11 @@ function encodeStoredItem(data) {
|
||||
* @param {*} 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 {
|
||||
if(!Array.isArray(data)) return data;
|
||||
if (!Array.isArray(data)) return data;
|
||||
return new SBMap(id, data);
|
||||
} catch(e) {
|
||||
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)
|
||||
if (typeof data === "string") {
|
||||
try {
|
||||
let str = JSON.parse(data);
|
||||
|
||||
if(Array.isArray(data)) {
|
||||
return new SBMap(id, str)
|
||||
if (Array.isArray(data)) {
|
||||
return new SBMap(id, str);
|
||||
}
|
||||
} catch(e) {
|
||||
// Continue normally (out of this if statement)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user