Browse Source

Make sure REPL doesn't get borked when invalid REPL keywords are entered

v0.7.4-release
Brian White 14 years ago
committed by Ryan Dahl
parent
commit
e41e078159
  1. 10
      lib/repl.js

10
lib/repl.js

@ -84,6 +84,7 @@ function REPLServer(prompt, stream) {
}); });
rli.addListener('line', function(cmd) { rli.addListener('line', function(cmd) {
var skipCatchall = false;
cmd = trimWhitespace(cmd); cmd = trimWhitespace(cmd);
// Check to see if a REPL keyword was used. If it returns true, // Check to see if a REPL keyword was used. If it returns true,
@ -92,9 +93,15 @@ function REPLServer(prompt, stream) {
var matches = cmd.match(/^(\.[^\s]+)\s*(.*)$/); var matches = cmd.match(/^(\.[^\s]+)\s*(.*)$/);
var keyword = matches && matches[1]; var keyword = matches && matches[1];
var rest = matches && matches[2]; var rest = matches && matches[2];
if (self.parseREPLKeyword(keyword, rest) === true) return; if (self.parseREPLKeyword(keyword, rest) === true) {
return;
} else {
self.stream.write('Invalid REPL keyword\n');
skipCatchall = true;
}
} }
if (!skipCatchall) {
// The catchall for errors // The catchall for errors
try { try {
self.buffered_cmd += cmd; self.buffered_cmd += cmd;
@ -130,6 +137,7 @@ function REPLServer(prompt, stream) {
} }
self.buffered_cmd = ''; self.buffered_cmd = '';
} }
}
self.displayPrompt(); self.displayPrompt();
}); });

Loading…
Cancel
Save