Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 4ea4e72

Browse files
addaleaxBethGriggs
authored andcommittedApr 15, 2021
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: #22436 PR-URL: #38209 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Yongsheng Zhang <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent 21d777b commit 4ea4e72

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed
 

‎lib/repl.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ function REPLServer(prompt,
651651
errStack = self.writer(e);
652652

653653
// Remove one line error braces to keep the old style in place.
654-
if (errStack[errStack.length - 1] === ']') {
654+
if (errStack[0] === '[' && errStack[errStack.length - 1] === ']') {
655655
errStack = StringPrototypeSlice(errStack, 1, -1);
656656
}
657657
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
'use strict';
2+
require('../common');
3+
const { PassThrough } = require('stream');
4+
const assert = require('assert');
5+
const repl = require('repl');
6+
7+
{
8+
const input = new PassThrough();
9+
const output = new PassThrough();
10+
11+
const r = repl.start({
12+
prompt: '',
13+
input,
14+
output,
15+
writer: String,
16+
terminal: false,
17+
useColors: false
18+
});
19+
20+
r.write('throw new Error("foo[a]")\n');
21+
r.close();
22+
assert.strictEqual(output.read().toString(), 'Uncaught Error: foo[a]\n');
23+
}

0 commit comments

Comments
 (0)
Please sign in to comment.