Narrow emoji >=U+10000 make WriteCharsLegacy sad ("wrong character insertion when scrolling to bash history") #9094

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

Originally created by @francogp on GitHub (Jun 18, 2020).

Originally assigned to: @lhecker on GitHub.

Notes from https://github.com/microsoft/terminal/issues/6555#issuecomment-646206984

[0x4]   OpenConsoleFullPDB!IsGlyphFullWidth + 0x9   
[0x5]   OpenConsoleFullPDB!WriteCharsLegacy + 0x2a3                  <<<<<<<<<<<<<<<<<
[0x6]   OpenConsoleFullPDB!WriteBuffer::_DefaultStringCase + 0xaf   
[0x7]   OpenConsoleFullPDB!WriteBuffer::PrintString + 0x16   
[0x8]   OpenConsoleFullPDB!Microsoft::Console::VirtualTerminal::AdaptDispatch::PrintString + 0x61   
[0x9]   OpenConsoleFullPDB!Microsoft::Console::VirtualTerminal::OutputStateMachineEngine::ActionPrintString + 0x42   
[0xa]   OpenConsoleFullPDB!Microsoft::Console::VirtualTerminal::StateMachine::ProcessString + 0x197   

We're calling IsGlyphFullWidth once for each half of the surrogate pair. You can well imagine how nicely that works out.


Environment

Windows build number: Win32NT 10.0.19041.0 Microsoft Windows NT 10.0.19041.0
Windows Terminal version (if applicable): 1.0.1402.0

Using WSL Ubuntu LTS version 20.04

Steps to reproduce

  1. Install Microsoft Terminal from Windows Store. Keep the default settings.
  2. Enable WSL and install Ubuntu 20.04 from Windows Store.
  3. Start Ubuntu 20.04 via WSL2.
  4. When bash prompt appears, run exactly this (from the first character until the end):
echo 🔥🌡  

the utf-16 equivalent (just to see the exact characters)

\u0065\u0063\u0068\u006f\u0020\ud83d\udd25\ud83c\udf21\u0020\u0020
  1. Press enter to see the result.
  2. Press key UP
  3. Press key DOWN
  4. Go to step 6.

Expected behavior

switch from

echo 🔥🌡  

to


THIS PROBLEM CANNOT BE REPRODUCED ON OTHER TERMINAL EMULATORS

Actual behavior

character 'e' inserted at the beginning

Originally created by @francogp on GitHub (Jun 18, 2020). Originally assigned to: @lhecker on GitHub. _Notes from https://github.com/microsoft/terminal/issues/6555#issuecomment-646206984_ ``` [0x4] OpenConsoleFullPDB!IsGlyphFullWidth + 0x9 [0x5] OpenConsoleFullPDB!WriteCharsLegacy + 0x2a3 <<<<<<<<<<<<<<<<< [0x6] OpenConsoleFullPDB!WriteBuffer::_DefaultStringCase + 0xaf [0x7] OpenConsoleFullPDB!WriteBuffer::PrintString + 0x16 [0x8] OpenConsoleFullPDB!Microsoft::Console::VirtualTerminal::AdaptDispatch::PrintString + 0x61 [0x9] OpenConsoleFullPDB!Microsoft::Console::VirtualTerminal::OutputStateMachineEngine::ActionPrintString + 0x42 [0xa] OpenConsoleFullPDB!Microsoft::Console::VirtualTerminal::StateMachine::ProcessString + 0x197 ``` We're calling `IsGlyphFullWidth` once for each half of the surrogate pair. You can well imagine how nicely that works out. --- # Environment ```none Windows build number: Win32NT 10.0.19041.0 Microsoft Windows NT 10.0.19041.0 Windows Terminal version (if applicable): 1.0.1402.0 Using WSL Ubuntu LTS version 20.04 ``` # Steps to reproduce 1. Install Microsoft Terminal from Windows Store. Keep the default settings. 2. Enable WSL and install Ubuntu 20.04 from Windows Store. 3. Start Ubuntu 20.04 via WSL2. 4. When bash prompt appears, run exactly this (from the first character until the end): ```bash echo 🔥🌡 ``` the utf-16 equivalent (just to see the exact characters) ```none \u0065\u0063\u0068\u006f\u0020\ud83d\udd25\ud83c\udf21\u0020\u0020 ``` 5. Press enter to see the result. 6. Press key UP 7. Press key DOWN 8. Go to step 6. # Expected behavior switch from ```bash echo 🔥🌡 ``` to ```none ``` THIS PROBLEM CANNOT BE REPRODUCED ON OTHER TERMINAL EMULATORS # Actual behavior character 'e' inserted at the beginning ![](http://g.recordit.co/nrmLGQqtYF.gif)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#9094