node/test/parallel/test-repl-pretty-stack-custom-writer.js
Anna Henningsen e7391967c2
repl: fix error message printing
The REPL implementation would strip away the first and last character
of a formatted error message if it ended with `]` (but with the
obviously missing check for a starting `]`), leading to things like
`Uncaught rror: foo[a` being printed for input like `Error: foo[a]`.

Refs: https://github.com/nodejs/node/pull/22436

PR-URL: https://github.com/nodejs/node/pull/38209
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2021-04-13 09:48:06 -07:00

24 lines
484 B
JavaScript

'use strict';
require('../common');
const { PassThrough } = require('stream');
const assert = require('assert');
const repl = require('repl');
{
const input = new PassThrough();
const output = new PassThrough();
const r = repl.start({
prompt: '',
input,
output,
writer: String,
terminal: false,
useColors: false
});
r.write('throw new Error("foo[a]")\n');
r.close();
assert.strictEqual(output.read().toString(), 'Uncaught Error: foo[a]\n');
}