GeezerVison is showing github.com — readline: fix unicode line separators being ignored · nodejs/node@e2b94dc
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: lib/internal/readline/interface.js +9-2Lines changed: 9 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -78,8 +78,15 @@ const { StringDecoder } = require('string_decoder'); |
78 | 78 | const kHistorySize = 30; |
79 | 79 | const kMaxUndoRedoStackSize = 2048; |
80 | 80 | const kMincrlfDelay = 100; |
81 | | -// \r\n, \n, or \r followed by something other than \n |
82 | | -const lineEnding = /\r?\n|\r(?!\n)/g; |
| 81 | +/** |
| 82 | + * The end of a line is signaled by either one of the following: |
| 83 | + * - \r\n |
| 84 | + * - \n |
| 85 | + * - \r followed by something other than \n |
| 86 | + * - \u2028 (Unicode 'LINE SEPARATOR') |
| 87 | + * - \u2029 (Unicode 'PARAGRAPH SEPARATOR') |
| 88 | + */ |
| 89 | +const lineEnding = /\r?\n|\r(?!\n)|\u2028|\u2029/g; |
83 | 90 |
|
84 | 91 | const kLineObjectStream = Symbol('line object stream'); |
85 | 92 | const kQuestionCancel = Symbol('kQuestionCancel'); |
|
Collapse file
Copy file name to clipboard +18Lines changed: 18 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +'use strict'; |
| 2 | +const common = require('../common'); |
| 3 | +const assert = require('node:assert'); |
| 4 | +const readline = require('node:readline'); |
| 5 | +const { Readable } = require('node:stream'); |
| 6 | + |
| 7 | +const str = '012\n345\r67\r\n89\u{2028}ABC\u{2029}DEF'; |
| 8 | + |
| 9 | +const rli = new readline.Interface({ |
| 10 | + input: Readable.from(str), |
| 11 | +}); |
| 12 | + |
| 13 | +const linesRead = []; |
| 14 | +rli.on('line', (line) => linesRead.push(line)); |
| 15 | + |
| 16 | +rli.on('close', common.mustCall(() => { |
| 17 | + assert.deepStrictEqual(linesRead, ['012', '345', '67', '89', 'ABC', 'DEF']); |
| 18 | +})); |