-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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 <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
- 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); | ||
}); |