[PR #19768] Fix: Allow SGR color space ID 0 to be valid #31954

Open
opened 2026-01-31 09:50:35 +00:00 by claunia · 0 comments
Owner

Original Pull Request: https://github.com/microsoft/terminal/pull/19768

State: closed
Merged: Yes


Summary of the Pull Request

This PR fixes an issue where SGR color sequences containing a Color Space ID of 0 (e.g., \e[38:2:0:r:g:bm) were incorrectly rejected as invalid.

References and Relevant Issues

Closes #19547

Detailed Description of the Pull Request / Additional comments

The existing logic in adaptDispatchGraphics.cpp treats any non-empty Color Space ID as an invalid sequence, intended to catch malformed sequences where the Red component might be shifted.

However, according to ITU T.416, the Color Space ID parameter is defined, and a value of 0 is implementation-defined. It is widely accepted by other terminal emulators (like XTerm) as the default RGB color space. This change modifies the check to explicitly allow an ID of 0 while still rejecting other non-standard IDs, ensuring compatibility with tools that emit fully qualified T.416 sequences.

Validation Steps Performed

Verified manually in WSL/Bash using printf to send the specific SGR sequence.

Test Command: printf "\e[38:2:0:255:0:0mRED\e[m\n"

Result: The text now correctly renders in Red instead of the default foreground color.
Before:
Screenshot 2026-01-22 212609
After:
Screenshot 2026-01-22 212638

PR Checklist

**Original Pull Request:** https://github.com/microsoft/terminal/pull/19768 **State:** closed **Merged:** Yes --- ## Summary of the Pull Request This PR fixes an issue where SGR color sequences containing a Color Space ID of 0 (e.g., \e[38:2:0:r:g:bm) were incorrectly rejected as invalid. ## References and Relevant Issues Closes #19547 ## Detailed Description of the Pull Request / Additional comments The existing logic in adaptDispatchGraphics.cpp treats any non-empty Color Space ID as an invalid sequence, intended to catch malformed sequences where the Red component might be shifted. However, according to ITU T.416, the Color Space ID parameter is defined, and a value of 0 is implementation-defined. It is widely accepted by other terminal emulators (like XTerm) as the default RGB color space. This change modifies the check to explicitly allow an ID of 0 while still rejecting other non-standard IDs, ensuring compatibility with tools that emit fully qualified T.416 sequences. ## Validation Steps Performed Verified manually in WSL/Bash using printf to send the specific SGR sequence. Test Command: printf "\e[38:2:0:255:0:0mRED\e[m\n" Result: The text now correctly renders in Red instead of the default foreground color. Before: <img width="566" height="48" alt="Screenshot 2026-01-22 212609" src="https://github.com/user-attachments/assets/73017bf0-f081-4295-80dd-70ac6b3a9956" /> After: <img width="564" height="49" alt="Screenshot 2026-01-22 212638" src="https://github.com/user-attachments/assets/5aca3acc-2531-4229-8c37-8cde9cba6b46" /> ## PR Checklist - [x] Closes #19547 - [x] Tests added/passed - [ ] Documentation updated - If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/terminal) and link it here: #xxx - [ ] Schema updated (if necessary)
claunia added the pull-request label 2026-01-31 09:50:35 +00:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#31954