[PR #1850] Fix for UTF-8 partials in function ConhostConnection::_OutputThread. #24684

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

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

State: closed
Merged: Yes


Summary of the Pull Request

ConhostConnection::_OutputThread shall take care of partial UTF-8 characters generated while buffering the stream read.

References

This PR may partially fix the occurrence of � characters as seen on screenshots in the following issues:
#386 #455 #666

PR Checklist

  • Closes #xxx
  • CLA signed. If not, go over here and sign the CLA
  • Tests added/passed
  • Requires documentation to be updated
  • I've discussed this with core contributors already. If not checked, I'm ready to accept this work might be rejected in favor of a different grand plan. Issue number where discussion took place: #386

Detailed Description of the Pull Request / Additional comments

Code points are represented by a sequence of 1 to 4 bytes in UTF-8. Whenever UTF-8 text is getting buffered, code points that consist of multiple bytes may get split at the buffer boundaries. The buffer gets converted into a string of wchar_t where those partials are invalid and make MultiByteToWideChar replacing them with U+FFFD characters. The implementation needs to check whether or not the buffer ends with a partial character. If so, only convert the code points which are complete, and save the partial code units in a cache that gets prepended to the next chunk of text.

Remark:
The PR includes the removal of the UTF-8 Byte Order Mark if it is present at the beginning of the stream read.

Validation Steps Performed

Corresponding file UTF8OutPipeReaderTests.cpp added to the Types.Unit.Tests project.

**Original Pull Request:** https://github.com/microsoft/terminal/pull/1850 **State:** closed **Merged:** Yes --- <!-- Enter a brief description/summary of your PR here. What does it fix/what does it change/how was it tested (even manually, if necessary)? --> ## Summary of the Pull Request `ConhostConnection::_OutputThread` shall take care of partial UTF-8 characters generated while buffering the stream read. <!-- Other than the issue solved, is this relevant to any other issues/existing PRs? --> ## References This PR may partially fix the occurrence of � characters as seen on screenshots in the following issues: #386 #455 #666 <!-- Please review the items on the PR checklist before submitting--> ## PR Checklist * [ ] Closes #xxx * [x] CLA signed. If not, go over [here](https://cla.opensource.microsoft.com/microsoft/Terminal) and sign the CLA * [x] Tests added/passed * [ ] Requires documentation to be updated * [x] I've discussed this with core contributors already. If not checked, I'm ready to accept this work might be rejected in favor of a different grand plan. Issue number where discussion took place: #386 <!-- Provide a more detailed description of the PR, other things fixed or any additional comments/features here --> ## Detailed Description of the Pull Request / Additional comments Code points are represented by a sequence of 1 to 4 bytes in UTF-8. Whenever UTF-8 text is getting buffered, code points that consist of multiple bytes may get split at the buffer boundaries. The buffer gets converted into a string of wchar_t where those partials are invalid and make `MultiByteToWideChar` replacing them with U+FFFD characters. The implementation needs to check whether or not the buffer ends with a partial character. If so, only convert the code points which are complete, and save the partial code units in a cache that gets prepended to the next chunk of text. ~~Remark: The PR includes the removal of the UTF-8 Byte Order Mark if it is present at the beginning of the stream read.~~ <!-- Describe how you validated the behavior. Add automated tests wherever possible, but list manual validation steps taken as well --> ## Validation Steps Performed Corresponding file `UTF8OutPipeReaderTests.cpp` added to the `Types.Unit.Tests` project.
claunia added the pull-request label 2026-01-31 09:04:45 +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#24684