Skip to content

Commit

Permalink
readline: don't emit "line" events with a trailing '\n' char
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
TooTallNate committed Nov 7, 2012
1 parent fb6377e commit e95e095
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/readline.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions test/simple/test-readline-interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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();

Expand All @@ -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();

Expand All @@ -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]));
Expand Down

0 comments on commit e95e095

Please sign in to comment.