Skip to content

util.styleText is not respecting NO_COLOR when first argument is an array. #56717

Closed
@fisker

Description

@fisker

Version

v23.6.1

Platform

Windows 10

Subsystem

No response

What steps will reproduce the bug?

$ NO_COLOR=1 node -p "JSON.stringify(util.styleText('red', 'red'))"
"red"

$ NO_COLOR=1 node -p "JSON.stringify(util.styleText(['red'], 'red'))"
"\u001b[31mred\u001b[39m"

How often does it reproduce? Is there a required condition?

Always

What is the expected behavior? Why is that the expected behavior?

The two commands above should print the same result.

What do you see instead?

Different output.

Additional information

Looking at the implementation.

When the first argument is an array,

if (ArrayIsArray(format)) {
didn't call lazyUtilColors().shouldColorize, but it's checked when the first argument is a string
validateOneOf(key, 'format', ObjectKeys(inspect.colors));

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions