1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-12-04 15:58:05 +00:00

Introduce JSON parse utility function with error handling (#6401)

* Introduce JSON parse utility function with error handling

Fixes #6400

* Fix typo
This commit is contained in:
Jeremy Ruston
2022-02-21 15:29:25 +00:00
committed by GitHub
parent 5378b45c40
commit 82c8fe7fa8
18 changed files with 48 additions and 58 deletions

View File

@@ -33,7 +33,7 @@ Attempt to extract the tiddlers from an encrypted store area using the current p
exports.decryptStoreArea = function(encryptedStoreArea,password) {
var decryptedText = $tw.crypto.decrypt(encryptedStoreArea,password);
if(decryptedText) {
var json = JSON.parse(decryptedText),
var json = $tw.utils.parseJSONSafe(decryptedText),
tiddlers = [];
for(var title in json) {
if(title !== "$:/isEncrypted") {

View File

@@ -198,7 +198,7 @@ var importDataTypes = [
];
function parseJSONTiddlers(json,fallbackTitle) {
var data = JSON.parse(json);
var data = $tw.utils.parseJSONSafe(json);
if(!$tw.utils.isArray(data)) {
data = [data];
}

View File

@@ -30,11 +30,7 @@ exports.getEditionInfo = function() {
var entry = entries[entryIndex];
// Check if directories have a valid tiddlywiki.info
if(!editionInfo[entry] && $tw.utils.isDirectory(path.resolve(editionPath,entry))) {
var info;
try {
info = JSON.parse(fs.readFileSync(path.resolve(editionPath,entry,"tiddlywiki.info"),"utf8"));
} catch(ex) {
}
var info = $tw.utils.parseJSONSafe(fs.readFileSync(path.resolve(editionPath,entry,"tiddlywiki.info"),"utf8"),null);
if(info) {
editionInfo[entry] = info;
}

View File

@@ -24,10 +24,8 @@ exports.repackPlugin = function(title,additionalTiddlers,excludeTiddlers) {
throw "No such tiddler as " + title;
}
// Extract the JSON
var jsonPluginTiddler;
try {
jsonPluginTiddler = JSON.parse(pluginTiddler.fields.text);
} catch(e) {
var jsonPluginTiddler = $tw.utils.parseJSONSafe(pluginTiddler.fields.text,null);
if(!jsonPluginTiddler) {
throw "Cannot parse plugin tiddler " + title + "\n" + $tw.language.getString("Error/Caption") + ": " + e;
}
// Get the list of tiddlers