Skip to content

Commit

Permalink
repl: removing the buggy trimWhitespace function
Browse files Browse the repository at this point in the history
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 removes the function and uses a proper RegEx which will
match all the whitespace characters at the beginning and ending of the
string and replaces the matched whitespace characters with empty string
  • Loading branch information
thefourtheye committed Jul 21, 2015
1 parent b612f08 commit cde9a65
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 14 deletions.
14 changes: 1 addition & 13 deletions lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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, '\\$&');
}
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';
8 changes: 7 additions & 1 deletion test/parallel/test-repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
]);
}

Expand Down

0 comments on commit cde9a65

Please sign in to comment.