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 4ae2492

Browse filesBrowse files
aduh95ruyadorno
authored andcommitted
readline: fix detection of carriage return
Fixes: #45992 PR-URL: #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>
1 parent 1d44017 commit 4ae2492
Copy full SHA for 4ae2492

File tree

Expand file treeCollapse file tree

3 files changed

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

3 files changed

+24
-42
lines changed
Open diff view settings
Collapse file

‎lib/internal/readline/interface.js‎

Copy file name to clipboardExpand all lines: lib/internal/readline/interface.js
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,7 @@ class Interface extends InterfaceConstructor {
598598
if (this[kLine_buffer]) {
599599
string = this[kLine_buffer] + string;
600600
this[kLine_buffer] = null;
601+
lineEnding.lastIndex = 0; // Start the search from the beginning of the string.
601602
newPartContainsEnding = RegExpPrototypeExec(lineEnding, string);
602603
}
603604
this[kSawReturnAt] = StringPrototypeEndsWith(string, '\r') ?
Collapse file

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

Copy file name to clipboardExpand all lines: test/known_issues/test-readline-big-file-carriage-return.js
-42Lines changed: 0 additions & 42 deletions
This file was deleted.
Collapse file
+23Lines changed: 23 additions & 0 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.