diff --git a/lib/readline.js b/lib/readline.js index add3a6a4bd9..a3f1b9d5801 100644 --- a/lib/readline.js +++ b/lib/readline.js @@ -310,11 +310,14 @@ Interface.prototype._normalWrite = function(b) { this._sawReturn = false; } + // Run test() on the new string chunk, not on the entire line buffer. + var newPartContainsEnding = lineEnding.test(string); + if (this._line_buffer) { string = this._line_buffer + string; this._line_buffer = null; } - if (lineEnding.test(string)) { + if (newPartContainsEnding) { this._sawReturn = /\r$/.test(string); // got one or more newlines; process into "line" events