forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 3
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: nodejs#16485 (comment)
- Loading branch information
1 parent
df79b7d
commit e8eeacd
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); | ||
}); |