Repository navigation
Merge surrogate pairs in Windows VT100 console input - #2124
Open
Cherith1222 wants to merge 1 commit into
Open
Cherith1222 wants to merge 1 commit into
Cherith1222 wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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,Win32InputusesVt100ConsoleInputReader. The console delivers that character as two key events, a high and a low UTF-16 surrogate.ConsoleInputReader.readalready merges the pair in_merge_paired_surrogates.Vt100ConsoleInputReader.readfed each half to the VT100 parser by itself. It now joins the key data from that read and runsencode("utf-16-le", "surrogatepass").decode("utf-16-le", "surrogatepass"), so a high/low pair becomes one character beforefeed.tests/test_win32_input.pyfeedsa,\ud83c,\udd32, andbthrough a fakeReadConsoleInputWand expects the keysa, U+1F132, andb. The test is skipped unlesssys.platform == "win32".On 2026-10-08,
ghfor headadda06422be35dd290ac04404af982dd76030ef0showed sixtest-ubunturuns (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.