node/test/parallel/test-readline-carriage-return-between-chunks.js
Antoine du Hamel e8d40154d8
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>
2023-01-24 12:10:11 +00:00

24 lines
522 B
JavaScript

'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);
}));