Skip to content

Fix invalid ANSI SGR escape code in JSON and diff colorization#12720

Open
BagToad wants to merge 1 commit intotrunkfrom
kw/fix-invalid-ansi
Open

Fix invalid ANSI SGR escape code in JSON and diff colorization#12720
BagToad wants to merge 1 commit intotrunkfrom
kw/fix-invalid-ansi

Conversation

@BagToad
Copy link
Member

@BagToad BagToad commented Feb 19, 2026

Fix invalid ANSI SGR escape code in JSON and diff colorization

Fixes #12683

Description

The delimiter/header color constant 1;38 produces an invalid ANSI escape sequence. SGR parameter 38 is the extended foreground color prefix and requires sub-parameters (e.g. 38;5;n for 256-color or 38;2;r;g;b for 24-bit). Using it bare with m is undefined behavior.

References

This is specified in:

I guess most terminals silently ignore the malformed 38 and only apply 1 (bold), which is why this went unnoticed since the code was introduced in #1114 (June 2020). The comment // bright white alludes to the original intent being a white color; 38 appears to have been a typo for 37.

Changes

Replace 1;38 with 1;37 (bold white) in:

  • pkg/jsoncolor/jsoncolor.go: used for JSON delimiters ({}[]:,)
  • pkg/cmd/pr/diff/diff.go: used for diff headers

Replace `1;38` with `1;37` (bold white) in the delimiter/header
color constant. SGR parameter 38 is the extended foreground color
prefix and requires sub-parameters (e.g. `38;5;n` or `38;2;r;g;b`),
so using it bare produces an invalid escape sequence. Most terminals
silently ignore the malformed parameter, masking the bug.

Fixes #12683

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes invalid ANSI SGR sequences emitted by gh when colorizing JSON output and PR diffs by replacing the malformed ESC[1;38m (bare 38) with the valid ESC[1;37m (bold/bright-ish white in many terminals), resolving #12683.

Changes:

  • Replace 1;38 with 1;37 for JSON delimiter coloring.
  • Replace 1;38 with 1;37 for diff header coloring.
  • Update unit tests to assert the corrected escape sequences.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
pkg/jsoncolor/jsoncolor.go Fix JSON delimiter ANSI SGR constant to a valid code (1;37).
pkg/jsoncolor/jsoncolor_test.go Update expected JSON output to match corrected delimiter color.
pkg/cmd/pr/diff/diff.go Fix diff header ANSI SGR sequence to a valid code (1;37).
pkg/cmd/pr/diff/diff_test.go Update expected diff output to match corrected header color.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Invalid ANSI codes generated by gh api repos/walles/moor/issues/384

2 participants