From 0bf97a53e06e9d1c59e9785363a03c223dbde7db Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Fri, 6 Dec 2024 15:52:05 -0800 Subject: [PATCH] cli: respect `$NO_COLOR` only if it's non-empty This is what the spec says. --- CHANGELOG.md | 2 ++ cli/src/config.rs | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d078663479..fb23c08412 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,8 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ### Fixed bugs +* The `$NO_COLOR` environment variable must now be non-empty to be respected. + ## [0.24.0] - 2024-12-04 ### Release highlights diff --git a/cli/src/config.rs b/cli/src/config.rs index 426409b598..d0bbca007b 100644 --- a/cli/src/config.rs +++ b/cli/src/config.rs @@ -359,7 +359,7 @@ pub fn config_from_environment(default: config::Config) -> StackedConfig { /// Environment variables that should be overridden by config values fn env_base() -> config::Config { let mut builder = config::Config::builder(); - if env::var("NO_COLOR").is_ok() { + if !env::var("NO_COLOR").unwrap_or_default().is_empty() { // "User-level configuration files and per-instance command-line arguments // should override $NO_COLOR." https://no-color.org/ builder = builder.set_override("ui.color", "never").unwrap();