Fix invalid ANSI SGR escape code in JSON and diff colorization#12720
Open
Fix invalid ANSI SGR escape code in JSON and diff colorization#12720
Conversation
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>
Contributor
There was a problem hiding this comment.
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;38with1;37for JSON delimiter coloring. - Replace
1;38with1;37for 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix invalid ANSI SGR escape code in JSON and diff colorization
Fixes #12683
Description
The delimiter/header color constant
1;38produces an invalid ANSI escape sequence. SGR parameter38is the extended foreground color prefix and requires sub-parameters (e.g.38;5;nfor 256-color or38;2;r;g;bfor 24-bit). Using it bare withmis undefined behavior.References
This is specified in:
38requires5;nor2;r;g;b38must be followed by;5;nor;2;r;g;bI guess most terminals silently ignore the malformed
38and only apply1(bold), which is why this went unnoticed since the code was introduced in #1114 (June 2020). The comment// bright whitealludes to the original intent being a white color;38appears to have been a typo for37.Changes
Replace
1;38with1;37(bold white) in:pkg/jsoncolor/jsoncolor.go: used for JSON delimiters ({}[]:,)pkg/cmd/pr/diff/diff.go: used for diff headers