Browse Source

repl: make invalid RegExp modifiers throw in the REPL

Fixes #4012.
v0.8.12-release
Nathan Rajlich 13 years ago
parent
commit
f1722a280c
  1. 1
      lib/repl.js
  2. 4
      test/simple/test-repl.js

1
lib/repl.js

@ -273,6 +273,7 @@ function REPLServer(prompt, stream, eval_, useGlobal, ignoreUndefined) {
return e && e.match(/^SyntaxError/) && return e && e.match(/^SyntaxError/) &&
// RegExp syntax error // RegExp syntax error
!e.match(/^SyntaxError: Invalid regular expression/) && !e.match(/^SyntaxError: Invalid regular expression/) &&
!e.match(/^SyntaxError: Invalid flags supplied to RegExp constructor/) &&
// JSON.parse() error // JSON.parse() error
!(e.match(/^SyntaxError: Unexpected token .*\n/) && !(e.match(/^SyntaxError: Unexpected token .*\n/) &&
e.match(/\n at Object.parse \(native\)\n/)); e.match(/\n at Object.parse \(native\)\n/));

4
test/simple/test-repl.js

@ -130,6 +130,10 @@ function error_test() {
// should throw // should throw
{ client: client_unix, send: '/(/;', { client: client_unix, send: '/(/;',
expect: /^SyntaxError: Invalid regular expression\:/ }, expect: /^SyntaxError: Invalid regular expression\:/ },
// invalid RegExp modifiers are a special case of syntax error,
// should throw (GH-4012)
{ client: client_unix, send: 'new RegExp("foo", "wrong modifier");',
expect: /^SyntaxError: Invalid flags supplied to RegExp constructor/ },
// Named functions can be used: // Named functions can be used:
{ client: client_unix, send: 'function blah() { return 1; }', { client: client_unix, send: 'function blah() { return 1; }',
expect: prompt_unix }, expect: prompt_unix },

Loading…
Cancel
Save