Skip to content

Commit e95e095

Browse files
committed
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.
1 parent fb6377e commit e95e095

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

lib/readline.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ Interface.prototype._normalWrite = function(b) {
308308
string = lines.pop();
309309
this._line_buffer = string;
310310
lines.forEach(function(line) {
311-
this._onLine(line + '\n');
311+
this._onLine(line);
312312
}, this);
313313
} else if (string) {
314314
// no newlines this time, save what we have for next time

test/simple/test-readline-interface.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ rli = new readline.Interface(fi, {});
4343
called = false;
4444
rli.on('line', function(line) {
4545
called = true;
46-
assert.equal(line, 'asdf\n');
46+
assert.equal(line, 'asdf');
4747
});
4848
fi.emit('data', 'asdf\n');
4949
assert.ok(called);
@@ -54,7 +54,7 @@ rli = new readline.Interface(fi, {});
5454
called = false;
5555
rli.on('line', function(line) {
5656
called = true;
57-
assert.equal(line, '\n');
57+
assert.equal(line, '');
5858
});
5959
fi.emit('data', '\n');
6060
assert.ok(called);
@@ -76,7 +76,7 @@ rli = new readline.Interface(fi, {});
7676
called = false;
7777
rli.on('line', function(line) {
7878
called = true;
79-
assert.equal(line, 'a\n');
79+
assert.equal(line, 'a');
8080
});
8181
fi.emit('data', 'a');
8282
assert.ok(!called);
@@ -93,7 +93,7 @@ rli.on('line', function(line) {
9393
assert.equal(line, expectedLines[callCount]);
9494
callCount++;
9595
});
96-
fi.emit('data', expectedLines.join(''));
96+
fi.emit('data', expectedLines.join('\n') + '\n');
9797
assert.equal(callCount, expectedLines.length);
9898
rli.close();
9999

@@ -106,7 +106,7 @@ rli.on('line', function(line) {
106106
assert.equal(line, expectedLines[callCount]);
107107
callCount++;
108108
});
109-
fi.emit('data', expectedLines.join(''));
109+
fi.emit('data', expectedLines.join('\n'));
110110
assert.equal(callCount, expectedLines.length - 1);
111111
rli.close();
112112

@@ -117,7 +117,7 @@ rli = new readline.Interface(fi, {});
117117
callCount = 0;
118118
rli.on('line', function(line) {
119119
callCount++;
120-
assert.equal(line, buf.toString('utf8') + '\n');
120+
assert.equal(line, buf.toString('utf8'));
121121
});
122122
[].forEach.call(buf, function(i) {
123123
fi.emit('data', Buffer([i]));

0 commit comments

Comments
 (0)