Skip to content

NO_COLOR implementation differs from the spec: also honors the variable if its value is empty #21198

Open

Description

Prerequisites

Steps to reproduce

Tangentially related: #21186

The https://no-color.org/ specification states (emphasis added):

should check for a NO_COLOR environment variable that, when present and not an empty string (regardless of its value), prevents the addition of ANSI color.

By contrast, PowerShell currently bases its behavior purely on the existence of this environment variable, and therefore also considers an empty variable (one whose value is the empty string) as requesting color opt-out.

# Run from a POSIX-like shell, such as Bash

# Non-empty value: OK 
NO_COLOR=1 pwsh -noprofile -c '$PSStyle.OutputRendering'

# Empty value: !! Unexpectedly treated like a non-empty value.
NO_COLOR= pwsh -noprofile -c '$PSStyle.OutputRendering'

As an aside:

  • What the spec prescribes doesn't align with common practice for flag-like environment variables on Unix-like platforms: usually, for variables whose value doesn't matter, it is just the existence vs. non-existence that governs behavior.

  • The variant behavior does have one advantage, however: it allows calls such as NO_COLOR= foo ... (from POSIX-compatible shells) as an ad-hoc, child process-scoped opt-out out of non-coloring, which would otherwise not be possible, as this syntax doesn't support undefining (removing) environment variables ad hoc.

Expected behavior

PlainText
Host

That is:

  • the existence of NO_COLOR with a non-empty value should cause PowerShell to set $PSStyle.OutputRendering to PlainText
  • whereas an empty value should not.

Actual behavior

PlainText
PlainText

Error details

No response

Environment data

PowerShell 7.5.0-preview.1 on Unix-like platforms.

Visuals

No response

Activity

  1. added
    Needs-Triage
    on Feb 7, 2024
  2. rhubarb-geek-nz commented on Feb 8, 2024

    @rhubarb-geek-nz

    Given PowerShell is listed at NO_COLOR it would be good to have strict conformance with the specification and lead by example.

  3. changed the title [-]`NO_COLOR` implementation differs from the spec.: also honors the variable if its value is empty[/-] [+]`NO_COLOR` implementation differs from the spec: also honors the variable if its value is empty[/+] on Feb 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs-Triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions