Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
readline: fix detection of carriage return
Fixes: #45992
  • Loading branch information
aduh95 committed Jan 22, 2023
commit cffcbd9103e476a35c1417b5ee63b540b74c48e4
1 change: 1 addition & 0 deletions lib/internal/readline/interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,7 @@ class Interface extends InterfaceConstructor {
if (this[kLine_buffer]) {
string = this[kLine_buffer] + string;
this[kLine_buffer] = null;
lineEnding.lastIndex = 0; // Start the search from the beginning of the string.
newPartContainsEnding = RegExpPrototypeExec(lineEnding, string);
}
this[kSawReturnAt] = StringPrototypeEndsWith(string, '\r') ?
Expand Down
42 changes: 0 additions & 42 deletions test/known_issues/test-readline-big-file-carriage-return.js

This file was deleted.

23 changes: 23 additions & 0 deletions test/parallel/test-readline-carriage-return-between-chunks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'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);
}));