Skip to content

Commit 362a7c0

Browse files
shivanthMylesBorins
authored andcommitted
repl: do not consider ... as a REPL command
This fix makes ... in REPL to be considered as a javascript construct rather than a REPL keyword. Fixes: #14426 Backport-PR-URL: #14915 PR-URL: #14467 Reviewed-By: Roman Reiss <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]>
1 parent 90fcccd commit 362a7c0

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

lib/repl.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -519,10 +519,11 @@ function REPLServer(prompt,
519519

520520
// Check to see if a REPL keyword was used. If it returns true,
521521
// display next prompt and return.
522-
if (cmd && cmd.charAt(0) === '.' && isNaN(parseFloat(cmd))) {
523-
var matches = cmd.match(/^\.([^\s]+)\s*(.*)$/);
524-
var keyword = matches && matches[1];
525-
var rest = matches && matches[2];
522+
if (cmd && cmd.charAt(0) === '.' && cmd.charAt(1) !== '.' &&
523+
isNaN(parseFloat(cmd))) {
524+
const matches = cmd.match(/^\.([^\s]+)\s*(.*)$/);
525+
const keyword = matches && matches[1];
526+
const rest = matches && matches[2];
526527
if (self.parseREPLKeyword(keyword, rest) === true) {
527528
return;
528529
} else if (!self.bufferedCommand) {

test/parallel/test-repl.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,13 @@ function error_test() {
387387
{
388388
client: client_unix, send: '(function() {\nif (false) {} /bar"/;\n}())',
389389
expect: `${prompt_multiline}${prompt_multiline}undefined\n${prompt_unix}`
390-
}
390+
},
391+
// Do not parse `...[]` as a REPL keyword
392+
{ client: client_unix, send: '...[]\n',
393+
expect: `${prompt_multiline}` },
394+
// bring back the repl to prompt
395+
{ client: client_unix, send: '.break',
396+
expect: `${prompt_unix}` }
391397
]);
392398
}
393399

0 commit comments

Comments
 (0)