Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
repl: remove buggy trimWhiteSpace function
As it is, the trimWhitespace function will not remove the white sapce
characters at the end of the string, as the greedy capturing group .+
captures everything till end of the string, leaving \s* with nothing.

This patch replaces the buggy function with the built-in, String
prototype's trim function.
  • Loading branch information
thefourtheye committed Sep 18, 2015
commit efa366b00fb3a5f5bf83fdd48d2f45d57116e863
13 changes: 1 addition & 12 deletions lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,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,
Expand Down Expand Up @@ -975,17 +975,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, '\\$&');
}
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/repl-load.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = 'repl';
6 changes: 6 additions & 0 deletions test/parallel/test-repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,12 @@ function error_test() {
'RegExp.$6\nRegExp.$7\nRegExp.$8\nRegExp.$9\n',
expect: ['\'1\'\n', '\'2\'\n', '\'3\'\n', '\'4\'\n', '\'5\'\n', '\'6\'\n',
'\'7\'\n', '\'8\'\n', '\'9\'\n'].join(`${prompt_unix}`) },
// making sure that the lines entered are trimmed properly
{ 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 },
]);
}

Expand Down