Skip to content

Commit

Permalink
readline: fix detection of carriage return
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
aduh95 authored and ruyadorno committed Jan 31, 2023
1 parent 1d44017 commit 4ae2492
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 42 deletions.
1 change: 1 addition & 0 deletions lib/internal/readline/interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,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);
}));

0 comments on commit 4ae2492

Please sign in to comment.