Skip to content

Commit 85b3edc

Browse files
Aviv Kellermarco-ippolito
Aviv Keller
authored andcommitted
repl: catch \v and \r in new-line detection
PR-URL: #54512 Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Mohammed Keyvanzadeh <[email protected]> Reviewed-By: LiviaMedeiros <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
1 parent 397be8a commit 85b3edc

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

lib/internal/repl/utils.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -436,9 +436,9 @@ function setupPreview(repl, contextSymbol, bufferSymbol, active) {
436436

437437
// Line breaks are very rare and probably only occur in case of error
438438
// 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)}`;
442442
}
443443

444444
const result = repl.useColors ?
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
}

0 commit comments

Comments
 (0)