Skip to content

Commit 837ddcb

Browse files
alecmevjuanarbol
authored andcommitted
test: add failing test for readline with carriage return
PR-URL: #46075 Refs: #45992 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
1 parent d0b9be2 commit 837ddcb

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
'use strict';
2+
3+
// Context: https://github.com/nodejs/node/issues/45992
4+
5+
require('../common');
6+
7+
const assert = require('assert');
8+
const fs = require('fs');
9+
const readline = require('readline');
10+
11+
const tmpdir = require('../common/tmpdir');
12+
13+
tmpdir.refresh();
14+
fs.mkdtempSync(`${tmpdir.path}/`);
15+
const path = `${tmpdir.path}/foo`;
16+
const writeStream = fs.createWriteStream(path);
17+
18+
function write(iteration, callback) {
19+
for (; iteration < 16384; iteration += 1) {
20+
if (!writeStream.write('foo\r\n')) {
21+
writeStream.once('drain', () => write(iteration + 1, callback));
22+
return;
23+
}
24+
}
25+
26+
writeStream.end();
27+
callback();
28+
}
29+
30+
write(0, () => {
31+
const input = fs.createReadStream(path);
32+
const rl = readline.createInterface({ input, crlfDelay: Infinity });
33+
let carriageReturns = 0;
34+
35+
rl.on('line', (x) => {
36+
if (x.includes('\r')) carriageReturns += 1;
37+
});
38+
39+
rl.on('close', () => {
40+
assert.strictEqual(carriageReturns, 0);
41+
});
42+
});

0 commit comments

Comments
 (0)