Skip to content

Merge surrogate pairs in Windows VT100 console input - #2124

Open
Cherith1222 wants to merge 1 commit into
prompt-toolkit:mainfrom
Cherith1222:fix/1978-vt-input-surrogate-pairs
Open

Cherith1222 wants to merge 1 commit into
prompt-toolkit:mainfrom
Cherith1222:fix/1978-vt-input-surrogate-pairs

Conversation

@Cherith1222

@Cherith1222 Cherith1222 commented Oct 7, 2026 •

Copy link
Copy Markdown

Summary

Issue #1978 reports that pasting U+1F132 in Windows Terminal started inserting ?? in prompt-toolkit 3.0.49. When virtual terminal input is enabled, Win32Input uses Vt100ConsoleInputReader. The console delivers that character as two key events, a high and a low UTF-16 surrogate.

ConsoleInputReader.read already merges the pair in _merge_paired_surrogates. Vt100ConsoleInputReader.read fed each half to the VT100 parser by itself. It now joins the key data from that read and runs encode("utf-16-le", "surrogatepass").decode("utf-16-le", "surrogatepass"), so a high/low pair becomes one character before feed.

tests/test_win32_input.py feeds a, \ud83c, \udd32, and b through a fake ReadConsoleInputW and expects the keys a, U+1F132, and b. The test is skipped unless sys.platform == "win32".

On 2026-10-08, gh for head adda06422be35dd290ac04404af982dd76030ef0 showed six test-ubuntu runs (3.10, 3.11, 3.12, 3.13, 3.14, 3.14t), all success. Those jobs do not run this test.

Fixes #1978.

Drafted with Cursor.

Cherith reviewed this diff and confirmed it with the person who helped draft it.

Since 3.0.49, Windows uses Vt100ConsoleInputReader when virtual terminal input is available. The console reports a non-BMP character such as U+1F132 as two key events, one per UTF-16 surrogate. The VT100 reader fed both halves to the parser separately, so pasting such a character inserted two lone surrogates (shown as '??'). The legacy ConsoleInputReader already merges these pairs. Merge them in the VT100 reader too, before feeding the parser.

Fixes prompt-toolkit#1978

AI-assisted (Cursor). Not yet reviewed by a human.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3.0.49 broke pasting of some unicode chars

1 participant