-
Notifications
You must be signed in to change notification settings - Fork 30.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
repl: fix util.inspect() coloring regression
The `Object.assign()` calls introduced in commit 90a4390 ("repl: show proxies as Proxy objects") mutated their first argument, causing the `{ colors: true }` option from the REPL to leak over into the global `util.inspect.defaultOptions` object. Refs: #16485 (comment) PR-URL: #17565 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Timothy Gu <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
- Loading branch information
1 parent
88a9e2d
commit 727339e
Showing
2 changed files
with
33 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* eslint-disable quotes */ | ||
'use strict'; | ||
require('../common'); | ||
const { Duplex } = require('stream'); | ||
const { inspect } = require('util'); | ||
const { strictEqual } = require('assert'); | ||
const { REPLServer } = require('repl'); | ||
|
||
let output = ''; | ||
|
||
const inout = new Duplex({ decodeStrings: false }); | ||
inout._read = function() { | ||
this.push('util.inspect("string")\n'); | ||
this.push(null); | ||
}; | ||
inout._write = function(s, _, cb) { | ||
output += s; | ||
cb(); | ||
}; | ||
|
||
const repl = new REPLServer({ input: inout, output: inout, useColors: true }); | ||
|
||
process.on('exit', function() { | ||
// https://github.com/nodejs/node/pull/16485#issuecomment-350428638 | ||
// The color setting of the REPL should not have leaked over into | ||
// the color setting of `util.inspect.defaultOptions`. | ||
strictEqual(output.includes(`'\\'string\\''`), true); | ||
strictEqual(output.includes(`'\u001b[32m\\'string\\'\u001b[39m'`), false); | ||
strictEqual(inspect.defaultOptions.colors, false); | ||
strictEqual(repl.writer.options.colors, true); | ||
}); |