[PR #10847] [MERGED] Sanitize C1 control chars in SetConsoleTitle API #28258

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

📋 Pull Request Information

Original PR: https://github.com/microsoft/terminal/pull/10847
Author: @j4james
Created: 8/1/2021
Status: Merged
Merged: 8/2/2021
Merged by: @undefined

Base: mainHead: fix-title-control-chars


📝 Commits (5)

  • f3f9221 Sanitize C1 control chars in SetConsoleTitle.
  • bae851f Add a unit test checking that control chars are stripped.
  • 1cdb251 Correct spelling in comments.
  • a148106 Make the title sanitization more efficient.
  • 74f3449 And fix the formatting to keep the bot happy.

📊 Changes

2 files changed (+40 additions, -9 deletions)

View changed files

📝 src/host/getset.cpp (+5 -9)
📝 src/host/ut_host/ConptyOutputTests.cpp (+35 -0)

📄 Description

When the SetContoleTitle API is called with a title containing control
characters, we need to filter out those characters before we can forward
the title change over conpty as an escape sequence. If we don't do that,
the receiving terminal will end up executing the control characters
instead of updating the title. We were already filtering out the C0
control characters, but with this PR we're now filtering out C1 controls
characters as well.

I've simply updated the sanitizing routine in DoSrvSetConsoleTitleW to
filter our characters in the range 0x80 to 0x9F. This is in addition
to the C0 range (0x00 to 0x1F) that was already excluded.

Validation Steps Performed

I've added a conpty unit test that calls DoSrvSetConsoleTitleW with
titles containing a variety of C0 and C1 controls characters, and which
verifies that those characters are stripped from the title forwarded to
conpty.

I've also confirmed that the test case in issue #10312 is now working
correctly in Windows Terminal.

Closes #10312


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/microsoft/terminal/pull/10847 **Author:** [@j4james](https://github.com/j4james) **Created:** 8/1/2021 **Status:** ✅ Merged **Merged:** 8/2/2021 **Merged by:** [@undefined](undefined) **Base:** `main` ← **Head:** `fix-title-control-chars` --- ### 📝 Commits (5) - [`f3f9221`](https://github.com/microsoft/terminal/commit/f3f9221a20313e2658001083f1a40307be54dde3) Sanitize C1 control chars in SetConsoleTitle. - [`bae851f`](https://github.com/microsoft/terminal/commit/bae851f42b7a53907b55f2c0308233db63e8a281) Add a unit test checking that control chars are stripped. - [`1cdb251`](https://github.com/microsoft/terminal/commit/1cdb251d2eac2bd975876297dc868d69e7b08441) Correct spelling in comments. - [`a148106`](https://github.com/microsoft/terminal/commit/a1481063b8744f90bb8f90a043aa168aec49be20) Make the title sanitization more efficient. - [`74f3449`](https://github.com/microsoft/terminal/commit/74f3449bf3f9f8a3bcad8ce7fe1efa938da4fe69) And fix the formatting to keep the bot happy. ### 📊 Changes **2 files changed** (+40 additions, -9 deletions) <details> <summary>View changed files</summary> 📝 `src/host/getset.cpp` (+5 -9) 📝 `src/host/ut_host/ConptyOutputTests.cpp` (+35 -0) </details> ### 📄 Description When the `SetContoleTitle` API is called with a title containing control characters, we need to filter out those characters before we can forward the title change over conpty as an escape sequence. If we don't do that, the receiving terminal will end up executing the control characters instead of updating the title. We were already filtering out the C0 control characters, but with this PR we're now filtering out C1 controls characters as well. I've simply updated the sanitizing routine in `DoSrvSetConsoleTitleW` to filter our characters in the range `0x80` to `0x9F`. This is in addition to the C0 range (`0x00` to `0x1F`) that was already excluded. ## Validation Steps Performed I've added a conpty unit test that calls `DoSrvSetConsoleTitleW` with titles containing a variety of C0 and C1 controls characters, and which verifies that those characters are stripped from the title forwarded to conpty. I've also confirmed that the test case in issue #10312 is now working correctly in Windows Terminal. Closes #10312 --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
claunia added the pull-request label 2026-01-31 09:27:21 +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#28258