Skip to content

Commit 2f7319e

Browse files
aduh95juanarbol
authored andcommitted
readline: fix detection of carriage return
Fixes: #45992 PR-URL: #46306 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]>
1 parent d153a93 commit 2f7319e

File tree

3 files changed

+24
-42
lines changed

3 files changed

+24
-42
lines changed

lib/internal/readline/interface.js

+1
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,7 @@ class Interface extends InterfaceConstructor {
597597
if (this[kLine_buffer]) {
598598
string = this[kLine_buffer] + string;
599599
this[kLine_buffer] = null;
600+
lineEnding.lastIndex = 0; // Start the search from the beginning of the string.
600601
newPartContainsEnding = RegExpPrototypeExec(lineEnding, string);
601602
}
602603
this[kSawReturnAt] = StringPrototypeEndsWith(string, '\r') ?

test/known_issues/test-readline-big-file-carriage-return.js

-42
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
5+
const assert = require('node:assert');
6+
const readline = require('node:readline');
7+
const { Readable } = require('node:stream');
8+
9+
10+
const input = Readable.from((function*() {
11+
yield 'a\nb';
12+
yield '\r\n';
13+
})());
14+
const rl = readline.createInterface({ input, crlfDelay: Infinity });
15+
let carriageReturns = 0;
16+
17+
rl.on('line', (line) => {
18+
if (line.includes('\r')) carriageReturns++;
19+
});
20+
21+
rl.on('close', common.mustCall(() => {
22+
assert.strictEqual(carriageReturns, 0);
23+
}));

0 commit comments

Comments
 (0)