Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/internal/util/inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,8 @@ function stylizeWithColor(str, styleType) {
const style = inspect.styles[styleType];
if (style !== undefined) {
const color = inspect.colors[style];
return `\u001b[${color[0]}m${str}\u001b[${color[1]}m`;
if (color !== undefined)
return `\u001b[${color[0]}m${str}\u001b[${color[1]}m`;
}
return str;
}
Expand Down
6 changes: 6 additions & 0 deletions test/parallel/test-util-inspect.js
Original file line number Diff line number Diff line change
Expand Up @@ -2245,6 +2245,12 @@ assert.strictEqual(
assert.deepStrictEqual(inspect.colors[bgColor], [40 + i, 49]);
assert.deepStrictEqual(inspect.colors[`${bgColor}Bright`], [100 + i, 49]);
});

// Unknown colors are handled gracefully:
const stringStyle = inspect.styles.string;
inspect.styles.string = 'UNKNOWN';
assert.strictEqual(inspect('foobar', { colors: true }), 'foobar');
inspect.styles.string = stringStyle;
}

assert.strictEqual(
Expand Down