Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 940484b

Browse filesBrowse files
alecmevruyadorno
authored andcommitted
test: add failing test for readline with carriage return
PR-URL: #46075 Refs: #45992 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent f318a85 commit 940484b
Copy full SHA for 940484b

File tree

Expand file treeCollapse file tree

1 file changed

+42
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+42
-0
lines changed
Open diff view settings
Collapse file
+42Lines changed: 42 additions & 0 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.