Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

repl: make invalid RegExps throw in the REPL

Fixes #2746.
  • Loading branch information...
commit 4a2670740c0e8cb4831c2c089cc7de7337a55e80 1 parent f536eb1
@TooTallNate TooTallNate authored
Showing with 7 additions and 0 deletions.
  1. +3 −0  lib/repl.js
  2. +4 −0 test/simple/test-repl.js
View
3  lib/repl.js
@@ -271,6 +271,9 @@ function REPLServer(prompt, stream, eval_, useGlobal, ignoreUndefined) {
// Convert error to string
e = e && (e.stack || e.toString());
return e && e.match(/^SyntaxError/) &&
+ // RegExp syntax error
+ !e.match(/^SyntaxError: Invalid regular expression/) &&
+ // JSON.parse() error
!(e.match(/^SyntaxError: Unexpected token .*\n/) &&
e.match(/\n at Object.parse \(native\)\n/));
}
View
4 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/ },
+ // invalid RegExps are a special case of syntax error,
+ // should throw
+ { client: client_unix, send: '/(/;',
+ expect: /^SyntaxError: Invalid regular expression\:/ },
// Named functions can be used:
{ client: client_unix, send: 'function blah() { return 1; }',
expect: prompt_unix },
Please sign in to comment.
Something went wrong with that request. Please try again.