Skip to content

Quality: Potential false negative when color support object lacks stdout#2690

Open
tuanaiseo wants to merge 1 commit intosinonjs:mainfrom
tuanaiseo:contribai/improve/quality/potential-false-negative-when-color-supp
Open

Quality: Potential false negative when color support object lacks stdout#2690
tuanaiseo wants to merge 1 commit intosinonjs:mainfrom
tuanaiseo:contribai/improve/quality/potential-false-negative-when-color-supp

Conversation

@tuanaiseo
Copy link
Copy Markdown

Problem

Colorizer.colorize only disables ANSI codes when this.supportsColor.stdout === false. If supportsColor is missing, malformed, or has stdout undefined, the function still emits ANSI escapes, which can pollute logs in non-TTY environments.

Severity: medium
File: lib/sinon/colorizer.js

Solution

Use a stricter capability check, e.g. if (!this.supportsColor || !this.supportsColor.stdout) return str; and consider guarding constructor input shape.

Changes

  • lib/sinon/colorizer.js (modified)

Testing

  • Existing tests pass
  • Manual review completed
  • No new warnings/errors introduced

`Colorizer.colorize` only disables ANSI codes when `this.supportsColor.stdout === false`. If `supportsColor` is missing, malformed, or has `stdout` undefined, the function still emits ANSI escapes, which can pollute logs in non-TTY environments.

Affected files: colorizer.js

Signed-off-by: tuanaiseo <221258316+tuanaiseo@users.noreply.github.com>
@fatso83
Copy link
Copy Markdown
Contributor

fatso83 commented Apr 9, 2026

Seems fine, but this requires a tiny test for that conditional.

@fatso83
Copy link
Copy Markdown
Contributor

fatso83 commented Apr 11, 2026

I removed colorizer supports-color in the ESM rewrite.

@fatso83 fatso83 closed this Apr 11, 2026
@fatso83 fatso83 reopened this Apr 11, 2026
@fatso83
Copy link
Copy Markdown
Contributor

fatso83 commented Apr 11, 2026

A bit quick there, I will keep this open to see if the issue is still there

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants