Merge pull request #1999 from s1341/fix_json_is_bad

strip off trailing commas
This commit is contained in:
John McLear 2013-11-26 05:16:42 -08:00
commit 1fa2b32854
3 changed files with 11 additions and 8 deletions

View File

@ -24,7 +24,7 @@ var os = require("os");
var path = require('path');
var argv = require('./Cli').argv;
var npm = require("npm/lib/npm.js");
var vm = require('vm');
var jsonminify = require("jsonminify");
var log4js = require("log4js");
var randomString = require('ep_etherpad-lite/static/js/pad_utils').randomString;
@ -166,8 +166,8 @@ exports.reloadSettings = function reloadSettings() {
var settings;
try {
if(settingsStr) {
settings = vm.runInContext('exports = '+settingsStr, vm.createContext(), "settings.json");
settings = JSON.parse(JSON.stringify(settings)); // fix objects having constructors of other vm.context
settingsStr = jsonminify(settingsStr).replace(",]","]").replace(",}","}");
settings = JSON.parse(settingsStr);
}
}catch(e){
console.error('There was an error processing your settings.json file: '+e.message);

View File

@ -39,6 +39,7 @@
"languages4translatewiki" : "0.1.3",
"swagger-node-express" : "1.2.3",
"channels" : "0.0.x",
"jsonminify" : "0.2.2",
"measured" : "0.1.3"
},
"bin": { "etherpad-lite": "./node/server.js" },

View File

@ -55,6 +55,8 @@ $(document).ready(function () {
function isJSONClean(data){
var cleanSettings = JSON.minify(data);
// this is a bit naive. In theory some key/value might contain the sequences ',]' or ',}'
cleanSettings = cleanSettings.replace(",]","]").replace(",}","}");
try{
var response = jQuery.parseJSON(cleanSettings);
}