Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 85b3edc

Browse filesBrowse files
avivkellermarco-ippolito
authored andcommitted
repl: catch \v and \r in new-line detection
PR-URL: #54512 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com> Reviewed-By: LiviaMedeiros <livia@cirno.name> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent 397be8a commit 85b3edc
Copy full SHA for 85b3edc

File tree

Expand file treeCollapse file tree

2 files changed

+32
-3
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+32
-3
lines changed
Open diff view settings
Collapse file

‎lib/internal/repl/utils.js‎

Copy file name to clipboardExpand all lines: lib/internal/repl/utils.js
+3-3Lines changed: 3 additions & 3 deletions
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 ?
Collapse file
+29Lines changed: 29 additions & 0 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.