Browse Source

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: https://github.com/nodejs/node/issues/14426
PR-URL: https://github.com/nodejs/node/pull/14467
Reviewed-By: Roman Reiss <me@silverwind.io>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
v6
Shivanth MP 8 years ago
committed by Roman Reiss
parent
commit
46d3ff2af9
No known key found for this signature in database GPG Key ID: 2E62B41C93869443
  1. 3
      lib/repl.js
  2. 8
      test/parallel/test-repl.js

3
lib/repl.js

@ -419,7 +419,8 @@ function REPLServer(prompt,
// Check to see if a REPL keyword was used. If it returns true,
// display next prompt and return.
if (trimmedCmd) {
if (trimmedCmd.charAt(0) === '.' && isNaN(parseFloat(trimmedCmd))) {
if (trimmedCmd.charAt(0) === '.' && trimmedCmd.charAt(1) !== '.' &&
isNaN(parseFloat(trimmedCmd))) {
const matches = trimmedCmd.match(/^\.([^\s]+)\s*(.*)$/);
const keyword = matches && matches[1];
const rest = matches && matches[2];

8
test/parallel/test-repl.js

@ -414,7 +414,13 @@ function error_test() {
expect: `${prompt_multiline}'foo \\n'\n${prompt_unix}` },
// Whitespace is not evaluated.
{ client: client_unix, send: ' \t \n',
expect: prompt_unix }
expect: 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}` }
]);
}

Loading…
Cancel
Save