diff --git a/lib/repl.js b/lib/repl.js index 763e283816bb64..4104c7f1433016 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -272,7 +272,7 @@ function REPLServer(prompt, if (self._inTemplateLiteral) { self._inTemplateLiteral = false; } else { - cmd = trimWhitespace(cmd); + cmd = cmd.trim(); } // Check to see if a REPL keyword was used. If it returns true, @@ -944,18 +944,6 @@ function defineDefaultCommands(repl) { }); } - -function trimWhitespace(cmd) { - const trimmer = /^\s*(.+)\s*$/m; - var matches = trimmer.exec(cmd); - - if (matches && matches.length === 2) { - return matches[1]; - } - return ''; -} - - function regexpEscape(s) { return s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&'); } diff --git a/test/fixtures/repl-load.js b/test/fixtures/repl-load.js new file mode 100644 index 00000000000000..4dca31f60d561e --- /dev/null +++ b/test/fixtures/repl-load.js @@ -0,0 +1 @@ +module.exports = 'repl'; diff --git a/test/parallel/test-repl.js b/test/parallel/test-repl.js index 6911c591505fef..28591e0d62d5ce 100644 --- a/test/parallel/test-repl.js +++ b/test/parallel/test-repl.js @@ -189,7 +189,13 @@ function error_test() { { client: client_unix, send: 'url.format("http://google.com")', expect: 'http://google.com/' }, { client: client_unix, send: 'var path = 42; path', - expect: '42' } + expect: '42' }, + // making sure that the fixed trim logic works fine + { client: client_unix, send: ' \t .break \t \t ', + expect: prompt_unix }, + { client: client_unix, send: '.load ' + + require('path').join(common.fixturesDir, 'repl-load.js \t '), + expect: prompt_unix + '\'repl\'\n' + prompt_unix }, ]); }