GeezerVison is showing github.com — repl: catch `\v` and `\r` in new-line detection · nodejs/node@85b3edc
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/repl/utils.js +3-3Lines changed: 3 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -436,9 +436,9 @@ function setupPreview(repl, contextSymbol, bufferSymbol, active) { |
436 | 436 |
|
437 | 437 | // Line breaks are very rare and probably only occur in case of error |
438 | 438 | // messages with line breaks. |
439 | | - const lineBreakPos = StringPrototypeIndexOf(inspected, '\n'); |
440 | | - if (lineBreakPos !== -1) { |
441 | | - inspected = `${StringPrototypeSlice(inspected, 0, lineBreakPos)}`; |
| 439 | + const lineBreakMatch = RegExpPrototypeExec(/[\r\n\v]/, inspected); |
| 440 | + if (lineBreakMatch !== null) { |
| 441 | + inspected = `${StringPrototypeSlice(inspected, 0, lineBreakMatch.index)}`; |
442 | 442 | } |
443 | 443 |
|
444 | 444 | const result = repl.useColors ? |
|
Collapse file
Copy file name to clipboard +29Lines changed: 29 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const common = require('../common'); |
| 4 | +const ArrayStream = require('../common/arraystream'); |
| 5 | +const assert = require('assert'); |
| 6 | +const repl = require('repl'); |
| 7 | + |
| 8 | +common.skipIfInspectorDisabled(); |
| 9 | + |
| 10 | +const inputStream = new ArrayStream(); |
| 11 | +const outputStream = new ArrayStream(); |
| 12 | +repl.start({ |
| 13 | + input: inputStream, |
| 14 | + output: outputStream, |
| 15 | + useGlobal: false, |
| 16 | + terminal: true, |
| 17 | + useColors: true |
| 18 | +}); |
| 19 | + |
| 20 | +let output = ''; |
| 21 | +outputStream.write = (chunk) => output += chunk; |
| 22 | + |
| 23 | +for (const char of ['\\n', '\\v', '\\r']) { |
| 24 | + inputStream.emit('data', `"${char}"()`); |
| 25 | + // Make sure the output is on a single line |
| 26 | + assert.strictEqual(output, `"${char}"()\n\x1B[90mTypeError: "\x1B[39m\x1B[9G\x1B[1A`); |
| 27 | + inputStream.run(['']); |
| 28 | + output = ''; |
| 29 | +} |