readline: fix unicode line separators being ignored

PR-URL: https://github.com/nodejs/node/pull/57591
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Jordan Harband <ljharb@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Dario Piotrowicz 2025-03-22 18:47:55 +00:00 committed by James M Snell
parent dfaded80e1
commit a42bca5fa7
2 changed files with 27 additions and 2 deletions

View File

@ -78,8 +78,15 @@ const { StringDecoder } = require('string_decoder');
const kHistorySize = 30;
const kMaxUndoRedoStackSize = 2048;
const kMincrlfDelay = 100;
// \r\n, \n, or \r followed by something other than \n
const lineEnding = /\r?\n|\r(?!\n)/g;
/**
* The end of a line is signaled by either one of the following:
* - \r\n
* - \n
* - \r followed by something other than \n
* - \u2028 (Unicode 'LINE SEPARATOR')
* - \u2029 (Unicode 'PARAGRAPH SEPARATOR')
*/
const lineEnding = /\r?\n|\r(?!\n)|\u2028|\u2029/g;
const kLineObjectStream = Symbol('line object stream');
const kQuestionCancel = Symbol('kQuestionCancel');

View File

@ -0,0 +1,18 @@
'use strict';
const common = require('../common');
const assert = require('node:assert');
const readline = require('node:readline');
const { Readable } = require('node:stream');
const str = '012\n345\r67\r\n89\u{2028}ABC\u{2029}DEF';
const rli = new readline.Interface({
input: Readable.from(str),
});
const linesRead = [];
rli.on('line', (line) => linesRead.push(line));
rli.on('close', common.mustCall(() => {
assert.deepStrictEqual(linesRead, ['012', '345', '67', '89', 'ABC', 'DEF']);
}));