GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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
Filter options
  • lib/internal/repl
    • utils.js
  • test/parallel
    • test-repl-preview-newlines.js
Expand file treeCollapse file tree
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

‎test/parallel/test-repl-preview-newlines.js‎

Copy file name to clipboard
+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)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.