From e95e095289c8f043c0d1a8508b9952ae9684b4d9 Mon Sep 17 00:00:00 2001 From: Nathan Rajlich Date: Tue, 6 Nov 2012 14:54:58 -0800 Subject: [PATCH] readline: don't emit "line" events with a trailing '\n' char Before this commit, readline was inconsistent in whether or not it would emit "line" events with or without the trailing "\n" included. When "terminal" mode was true, then there would be no "\n", when it was false, then the "\n" would be present. However, the trailing "\n" doesn't add much, and most of the time people just end up stripping it manually. Part of #4243. --- lib/readline.js | 2 +- test/simple/test-readline-interface.js | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/readline.js b/lib/readline.js index a2640e13ce2..2d62cb5c468 100644 --- a/lib/readline.js +++ b/lib/readline.js @@ -308,7 +308,7 @@ Interface.prototype._normalWrite = function(b) { string = lines.pop(); this._line_buffer = string; lines.forEach(function(line) { - this._onLine(line + '\n'); + this._onLine(line); }, this); } else if (string) { // no newlines this time, save what we have for next time diff --git a/test/simple/test-readline-interface.js b/test/simple/test-readline-interface.js index 568b73a29b8..33a5e7a16e4 100644 --- a/test/simple/test-readline-interface.js +++ b/test/simple/test-readline-interface.js @@ -43,7 +43,7 @@ rli = new readline.Interface(fi, {}); called = false; rli.on('line', function(line) { called = true; - assert.equal(line, 'asdf\n'); + assert.equal(line, 'asdf'); }); fi.emit('data', 'asdf\n'); assert.ok(called); @@ -54,7 +54,7 @@ rli = new readline.Interface(fi, {}); called = false; rli.on('line', function(line) { called = true; - assert.equal(line, '\n'); + assert.equal(line, ''); }); fi.emit('data', '\n'); assert.ok(called); @@ -76,7 +76,7 @@ rli = new readline.Interface(fi, {}); called = false; rli.on('line', function(line) { called = true; - assert.equal(line, 'a\n'); + assert.equal(line, 'a'); }); fi.emit('data', 'a'); assert.ok(!called); @@ -93,7 +93,7 @@ rli.on('line', function(line) { assert.equal(line, expectedLines[callCount]); callCount++; }); -fi.emit('data', expectedLines.join('')); +fi.emit('data', expectedLines.join('\n') + '\n'); assert.equal(callCount, expectedLines.length); rli.close(); @@ -106,7 +106,7 @@ rli.on('line', function(line) { assert.equal(line, expectedLines[callCount]); callCount++; }); -fi.emit('data', expectedLines.join('')); +fi.emit('data', expectedLines.join('\n')); assert.equal(callCount, expectedLines.length - 1); rli.close(); @@ -117,7 +117,7 @@ rli = new readline.Interface(fi, {}); callCount = 0; rli.on('line', function(line) { callCount++; - assert.equal(line, buf.toString('utf8') + '\n'); + assert.equal(line, buf.toString('utf8')); }); [].forEach.call(buf, function(i) { fi.emit('data', Buffer([i]));