1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -05:00

fix: Deno.noColor should not be true when NO_COLOR is empty string (#21275)

Closes https://github.com/denoland/deno/issues/21274
This commit is contained in:
David Sherret 2023-11-20 15:58:22 -05:00 committed by GitHub
parent c97a97240b
commit 1eefe3e42b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 2 deletions

View file

@ -24,3 +24,32 @@ Deno.test(
assertEquals(output, "false\n");
},
);
Deno.test(
{ permissions: { run: true, read: true } },
async function denoNoColorTrueEmptyVar() {
const { stdout } = await new Deno.Command(Deno.execPath(), {
args: ["eval", "console.log(Deno.noColor)"],
env: {
// https://no-color.org/ -- should not be true when empty
NO_COLOR: "",
},
}).output();
const output = new TextDecoder().decode(stdout);
assertEquals(output, "false\n");
},
);
Deno.test(
{ permissions: { run: true, read: true } },
async function denoNoColorTrueEmptyVar() {
const { stdout } = await new Deno.Command(Deno.execPath(), {
args: ["eval", "console.log(Deno.noColor)"],
env: {
NO_COLOR: "1",
},
}).output();
const output = new TextDecoder().decode(stdout);
assertEquals(output, "true\n");
},
);

View file

@ -22,8 +22,11 @@ use termcolor::BufferWriter;
#[cfg(windows)]
use termcolor::ColorChoice;
static NO_COLOR: Lazy<bool> =
Lazy::new(|| std::env::var_os("NO_COLOR").is_some());
static NO_COLOR: Lazy<bool> = Lazy::new(|| {
std::env::var_os("NO_COLOR")
.map(|v| !v.is_empty())
.unwrap_or(false)
});
static IS_TTY: Lazy<bool> = Lazy::new(|| std::io::stdout().is_terminal());