From de6c0e6779c6478d9ceabbaa38ee464b6ee8e7be Mon Sep 17 00:00:00 2001 From: Alec Mev Date: Sun, 22 Jan 2023 11:21:48 +0200 Subject: [PATCH] test: add failing test for readline with carriage return PR-URL: https://github.com/nodejs/node/pull/46075 Refs: https://github.com/nodejs/node/issues/45992 Reviewed-By: James M Snell Reviewed-By: Yagiz Nizipli Reviewed-By: Antoine du Hamel --- .../test-readline-big-file-carriage-return.js | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 test/known_issues/test-readline-big-file-carriage-return.js diff --git a/test/known_issues/test-readline-big-file-carriage-return.js b/test/known_issues/test-readline-big-file-carriage-return.js new file mode 100644 index 00000000000000..7dfc918927eb26 --- /dev/null +++ b/test/known_issues/test-readline-big-file-carriage-return.js @@ -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); + }); +});