diff --git a/js/ArgParser.js b/js/ArgParser.js
index 0d892f7d0..f4906e41a 100755
--- a/js/ArgParser.js
+++ b/js/ArgParser.js
@@ -26,7 +26,7 @@ Options and their defaults are:
/*jslint node: true */
"use strict";
-var Sandbox = require("./Sandbox.js").Sandbox;
+var sandbox = require("./Sandbox.js").sandbox;
var ArgParser = function(argString,options) {
var parseToken = function(match,p) {
@@ -38,7 +38,7 @@ var ArgParser = function(argString,options) {
} else if(match[p+2]) { // Double-square-bracket quoted
n = match[p+2];
} else if(match[p+3]) { // Double-brace quoted
- n = options.allowEval === false ? match[p+3] : Sandbox(match[p+3],options.globals);
+ n = options.allowEval === false ? match[p+3] : sandbox(match[p+3],options.globals);
} else if(match[p+4]) { // Unquoted
n = match[p+4];
} else if(match[p+5]) { // empty quote
diff --git a/js/Sandbox.js b/js/Sandbox.js
index 3cc61eccc..3acab652a 100644
--- a/js/Sandbox.js
+++ b/js/Sandbox.js
@@ -6,16 +6,12 @@ Execute a fragment of JavaScript in a sandbox
\*/
(function(){
-/*jslint node: true */
+/*jslint evil: true, node: true */
"use strict";
var uglify = require("uglify-js");
-var safeEval = function(e) {
- return eval(e);
-};
-
-var Sandbox = function(code,globals) {
+var sandbox = function(code,globals) {
var globalNames = [],
globalValues = [],
collectGlobals = function(globals) {
@@ -34,7 +30,7 @@ var Sandbox = function(code,globals) {
});
// Compose the code
var out = [];
- out.push("(function(")
+ out.push("(function(");
out.push(globalNames.join(","));
out.push(") { return ");
out.push(code);
@@ -45,9 +41,15 @@ var Sandbox = function(code,globals) {
// Recompile the code
var compiledCode = uglify.uglify.gen_code(tree);
// Execute it
- return eval(compiledCode).apply(null,globalValues);
+ var result;
+ try {
+ result = eval(compiledCode).apply(null,globalValues);
+ } catch(err) {
+ result = "{{** Evaluation error: " + err + " **}}";
+ }
+ return result;
};
-exports.Sandbox = Sandbox;
+exports.sandbox = sandbox;
})();
\ No newline at end of file
diff --git a/test/wikitests/SeventhTiddler.html b/test/wikitests/SeventhTiddler.html
new file mode 100644
index 000000000..c0c644dad
--- /dev/null
+++ b/test/wikitests/SeventhTiddler.html
@@ -0,0 +1 @@
+4
SeventhTiddler
{{** Evaluation error: ReferenceError: window is not defined **}}
\ No newline at end of file
diff --git a/test/wikitests/SeventhTiddler.tid b/test/wikitests/SeventhTiddler.tid
new file mode 100644
index 000000000..31e3fcf73
--- /dev/null
+++ b/test/wikitests/SeventhTiddler.tid
@@ -0,0 +1,7 @@
+title: SeventhTiddler
+
+<>
+
+<>
+
+<>
diff --git a/test/wikitests/SeventhTiddler.txt b/test/wikitests/SeventhTiddler.txt
new file mode 100644
index 000000000..025a2c7e2
--- /dev/null
+++ b/test/wikitests/SeventhTiddler.txt
@@ -0,0 +1 @@
+4SeventhTiddler{{** Evaluation error: ReferenceError: window is not defined **}}
\ No newline at end of file
diff --git a/test/wikitests/SixthTiddler.html b/test/wikitests/SixthTiddler.html
index b9ef11a8d..380190616 100644
--- a/test/wikitests/SixthTiddler.html
+++ b/test/wikitests/SixthTiddler.html
@@ -1 +1 @@
-SixthTiddler
SixthTiddler
11 February 2011
Jermolene
\ No newline at end of file
+SixthTiddler
SixthTiddler
11 February 2011
Jermolene
\ No newline at end of file
diff --git a/test/wikitests/SixthTiddler.txt b/test/wikitests/SixthTiddler.txt
index 8a78b69f9..5d2c17db9 100644
--- a/test/wikitests/SixthTiddler.txt
+++ b/test/wikitests/SixthTiddler.txt
@@ -1 +1 @@
-SixthTiddlerSixthTiddler11 February 2011JermoleneFifth TiddlerFirstTiddlerFourth TiddlerSecondTiddlerSixthTiddlerThirdTiddler
\ No newline at end of file
+SixthTiddlerSixthTiddler11 February 2011JermoleneFifth TiddlerFirstTiddlerFourth TiddlerSecondTiddlerSeventhTiddlerSixthTiddlerThirdTiddler
\ No newline at end of file
diff --git a/wikitest.js b/wikitest.js
index 0e3ed4f82..b472d0d68 100644
--- a/wikitest.js
+++ b/wikitest.js
@@ -59,10 +59,10 @@ for(t=0; t