summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMarcel Klehr <mklehr@gmx.net>2012-07-08 18:59:46 +0200
committerMarcel Klehr <mklehr@gmx.net>2012-07-08 18:59:46 +0200
commit4c8f69b7c55f1a8ba8e8d338c2cee6bac0cc85c4 (patch)
tree9cb1238b24d49f41d63f5afbf823b73943596e5b /src
parent9ff3aa0ee07b38332acd3a0bc1805806c42c0532 (diff)
downloadetherpad-lite-4c8f69b7c55f1a8ba8e8d338c2cee6bac0cc85c4.zip
Use v8 to parse settings.json
Diffstat (limited to 'src')
-rw-r--r--src/node/utils/Settings.js32
1 files changed, 13 insertions, 19 deletions
diff --git a/src/node/utils/Settings.js b/src/node/utils/Settings.js
index e60446df..aeeb9015 100644
--- a/src/node/utils/Settings.js
+++ b/src/node/utils/Settings.js
@@ -24,6 +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');
/* Root path of the installation */
exports.root = path.normalize(path.join(npm.dir, ".."));
@@ -45,6 +46,7 @@ exports.dbType = "dirty";
* This setting is passed with dbType to ueberDB to set up the database
*/
exports.dbSettings = { "filename" : path.join(exports.root, "dirty.db") };
+
/**
* The default Text of a new pad
*/
@@ -102,33 +104,25 @@ exports.abiwordAvailable = function()
// Discover where the settings file lives
var settingsFilename = argv.settings || "settings.json";
-if (settingsFilename.charAt(0) != '/') {
- settingsFilename = path.normalize(path.join(root, settingsFilename));
-}
+settingsFilename = path.resolve(path.join(root, settingsFilename));
-var settingsStr
+var settingsStr;
try{
//read the settings sync
- settingsStr = fs.readFileSync(settingsFilename).toString();
+ settingsStr = fs.readFileSync(settingsFilename);
} catch(e){
console.warn('No settings file found. Using defaults.');
- settingsStr = '{}';
}
-
-//remove all comments
-settingsStr = settingsStr.replace(/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+/gm,"").replace(/#.*/g,"").replace(/\/\/.*/g,"");
-//try to parse the settings
+// try to parse the settings
var settings;
-try
-{
- settings = JSON.parse(settingsStr);
-}
-catch(e)
-{
- console.error("There is a syntax error in your settings.json file");
- console.error(e.message);
- process.exit(1);
+try {
+ if(settingsStr) {
+ settings = vm.runInContext('exports = '+settingsStr, vm.createContext(), "settings.json");
+ }
+}catch(e){
+ console.warn('There was an error processing your settings.json file. Using defaults.');
+ console.warn(e.message);
}
//loop trough the settings