From 3b7312d23af26d0c1bdcb977015bda7c4709f222 Mon Sep 17 00:00:00 2001 From: Nathan Rajlich Date: Mon, 1 Oct 2012 11:36:06 -0700 Subject: [PATCH] repl: make "end of input" JSON.parse() errors throw in the REPL --- lib/repl.js | 2 +- test/simple/test-repl.js | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/repl.js b/lib/repl.js index 6ebcdc1814..b10427a16f 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -275,7 +275,7 @@ function REPLServer(prompt, stream, eval_, useGlobal, ignoreUndefined) { !e.match(/^SyntaxError: Invalid regular expression/) && !e.match(/^SyntaxError: Invalid flags supplied to RegExp constructor/) && // JSON.parse() error - !(e.match(/^SyntaxError: Unexpected token .*\n/) && + !(e.match(/^SyntaxError: Unexpected (token .*|end of input)/) && e.match(/\n at Object.parse \(native\)\n/)); } diff --git a/test/simple/test-repl.js b/test/simple/test-repl.js index ff6b5f98ec..c673cd5024 100644 --- a/test/simple/test-repl.js +++ b/test/simple/test-repl.js @@ -126,6 +126,10 @@ function error_test() { // should throw { client: client_unix, send: 'JSON.parse(\'{invalid: \\\'json\\\'}\');', expect: /^SyntaxError: Unexpected token i/ }, + // end of input to JSON.parse error is special case of syntax error, + // should throw + { client: client_unix, send: 'JSON.parse(\'{\');', + expect: /^SyntaxError: Unexpected end of input/ }, // invalid RegExps are a special case of syntax error, // should throw { client: client_unix, send: '/(/;',