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 committed Jan 24, 2023
1 parent 7dd4583 commit e8d4015
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
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
@@ -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 e8d4015

Please sign in to comment.