Skip to content

Commit

Permalink
repl: do not consider ... as a REPL command
Browse files Browse the repository at this point in the history
This fix makes ... in REPL to be considered as a javascript construct
rather than a REPL keyword.

Fixes: nodejs#14426
PR-URL: nodejs#14467
Reviewed-By: Roman Reiss <me@silverwind.io>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
  • Loading branch information
shivanth committed Aug 18, 2017
1 parent 567acf6 commit 1e07864
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
24 changes: 14 additions & 10 deletions lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -519,16 +519,20 @@ function REPLServer(prompt,

// Check to see if a REPL keyword was used. If it returns true,
// display next prompt and return.
if (cmd && cmd.charAt(0) === '.' && isNaN(parseFloat(cmd))) {
var matches = cmd.match(/^\.([^\s]+)\s*(.*)$/);
var keyword = matches && matches[1];
var rest = matches && matches[2];
if (self.parseREPLKeyword(keyword, rest) === true) {
return;
} else if (!self.bufferedCommand) {
self.outputStream.write('Invalid REPL keyword\n');
finish(null);
return;
if (cmd) {
if (cmd.charAt(0) === '.' && cmd.charAt(1) !== '.' &&
isNaN(parseFloat(cmd))) {
const matches = cmd.match(/^\.([^\s]+)\s*(.*)$/);
const keyword = matches && matches[1];
const rest = matches && matches[2];
if (self.parseREPLKeyword(keyword, rest) === true) {
return;
}
if (!self.bufferedCommand) {
self.outputStream.write('Invalid REPL keyword\n');
finish(null);
return;
}
}
}

Expand Down
8 changes: 7 additions & 1 deletion test/parallel/test-repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,13 @@ function error_test() {
{
client: client_unix, send: '(function() {\nif (false) {} /bar"/;\n}())',
expect: `${prompt_multiline}${prompt_multiline}undefined\n${prompt_unix}`
}
},
// Do not parse `...[]` as a REPL keyword
{ client: client_unix, send: '...[]\n',
expect: `${prompt_multiline}` },
// bring back the repl to prompt
{ client: client_unix, send: '.break',
expect: `${prompt_unix}` }
]);
}

Expand Down

0 comments on commit 1e07864

Please sign in to comment.