Skip to content

Commit

Permalink
test: add failing test for readline with carriage return
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
alecmev authored and ruyadorno committed Jan 31, 2023
1 parent f318a85 commit 940484b
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions test/known_issues/test-readline-big-file-carriage-return.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
'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 comments on commit 940484b

Please sign in to comment.