mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
readline: fix detection of carriage return
Fixes: https://github.com/nodejs/node/issues/45992 PR-URL: https://github.com/nodejs/node/pull/46306 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
This commit is contained in:
parent
7dd4583825
commit
e8d40154d8
@ -590,6 +590,7 @@ class Interface extends InterfaceConstructor {
|
||||
if (this[kLine_buffer]) {
|
||||
string = this[kLine_buffer] + string;
|
||||
this[kLine_buffer] = null;
|
||||
lineEnding.lastIndex = 0; // Start the search from the beginning of the string.
|
||||
newPartContainsEnding = RegExpPrototypeExec(lineEnding, string);
|
||||
}
|
||||
this[kSawReturnAt] = StringPrototypeEndsWith(string, '\r') ?
|
||||
|
@ -1,42 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
// Context: https://github.com/nodejs/node/issues/45992
|
||||
|
||||
require('../common');
|
||||
|
||||
const assert = require('assert');
|
||||
const fs = require('fs');
|
||||
const readline = require('readline');
|
||||
|
||||
const tmpdir = require('../common/tmpdir');
|
||||
|
||||
tmpdir.refresh();
|
||||
fs.mkdtempSync(`${tmpdir.path}/`);
|
||||
const path = `${tmpdir.path}/foo`;
|
||||
const writeStream = fs.createWriteStream(path);
|
||||
|
||||
function write(iteration, callback) {
|
||||
for (; iteration < 16384; iteration += 1) {
|
||||
if (!writeStream.write('foo\r\n')) {
|
||||
writeStream.once('drain', () => write(iteration + 1, callback));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
writeStream.end();
|
||||
callback();
|
||||
}
|
||||
|
||||
write(0, () => {
|
||||
const input = fs.createReadStream(path);
|
||||
const rl = readline.createInterface({ input, crlfDelay: Infinity });
|
||||
let carriageReturns = 0;
|
||||
|
||||
rl.on('line', (x) => {
|
||||
if (x.includes('\r')) carriageReturns += 1;
|
||||
});
|
||||
|
||||
rl.on('close', () => {
|
||||
assert.strictEqual(carriageReturns, 0);
|
||||
});
|
||||
});
|
@ -0,0 +1,23 @@
|
||||
'use strict';
|
||||
|
||||
const common = require('../common');
|
||||
|
||||
const assert = require('node:assert');
|
||||
const readline = require('node:readline');
|
||||
const { Readable } = require('node:stream');
|
||||
|
||||
|
||||
const input = Readable.from((function*() {
|
||||
yield 'a\nb';
|
||||
yield '\r\n';
|
||||
})());
|
||||
const rl = readline.createInterface({ input, crlfDelay: Infinity });
|
||||
let carriageReturns = 0;
|
||||
|
||||
rl.on('line', (line) => {
|
||||
if (line.includes('\r')) carriageReturns++;
|
||||
});
|
||||
|
||||
rl.on('close', common.mustCall(() => {
|
||||
assert.strictEqual(carriageReturns, 0);
|
||||
}));
|
Loading…
Reference in New Issue
Block a user