mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
repl: catch \v
and \r
in new-line detection
PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
parent
0b9249e335
commit
c6d20a034d
@ -436,9 +436,9 @@ function setupPreview(repl, contextSymbol, bufferSymbol, active) {
|
||||
|
||||
// Line breaks are very rare and probably only occur in case of error
|
||||
// messages with line breaks.
|
||||
const lineBreakPos = StringPrototypeIndexOf(inspected, '\n');
|
||||
if (lineBreakPos !== -1) {
|
||||
inspected = `${StringPrototypeSlice(inspected, 0, lineBreakPos)}`;
|
||||
const lineBreakMatch = RegExpPrototypeExec(/[\r\n\v]/, inspected);
|
||||
if (lineBreakMatch !== null) {
|
||||
inspected = `${StringPrototypeSlice(inspected, 0, lineBreakMatch.index)}`;
|
||||
}
|
||||
|
||||
const result = repl.useColors ?
|
||||
|
29
test/parallel/test-repl-preview-newlines.js
Normal file
29
test/parallel/test-repl-preview-newlines.js
Normal file
@ -0,0 +1,29 @@
|
||||
'use strict';
|
||||
|
||||
const common = require('../common');
|
||||
const ArrayStream = require('../common/arraystream');
|
||||
const assert = require('assert');
|
||||
const repl = require('repl');
|
||||
|
||||
common.skipIfInspectorDisabled();
|
||||
|
||||
const inputStream = new ArrayStream();
|
||||
const outputStream = new ArrayStream();
|
||||
repl.start({
|
||||
input: inputStream,
|
||||
output: outputStream,
|
||||
useGlobal: false,
|
||||
terminal: true,
|
||||
useColors: true
|
||||
});
|
||||
|
||||
let output = '';
|
||||
outputStream.write = (chunk) => output += chunk;
|
||||
|
||||
for (const char of ['\\n', '\\v', '\\r']) {
|
||||
inputStream.emit('data', `"${char}"()`);
|
||||
// Make sure the output is on a single line
|
||||
assert.strictEqual(output, `"${char}"()\n\x1B[90mTypeError: "\x1B[39m\x1B[9G\x1B[1A`);
|
||||
inputStream.run(['']);
|
||||
output = '';
|
||||
}
|
Loading…
Reference in New Issue
Block a user