mirror of
https://github.com/anomalyco/opentui.git
synced 2026-04-25 13:06:00 +03:00
[PR #682] [MERGED] fix(input): handle surrogate pairs in stdin buffer #710
Labels
No labels
bug
core
documentation
feature
good first issue
help wanted
pull-request
question
react
solid
tmux
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/opentui#710
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/anomalyco/opentui/pull/682
Author: @hugojosefson
Created: 2/13/2026
Status: ✅ Merged
Merged: 2/13/2026
Merged by: @simonklee
Base:
main← Head:fix/stdin-surrogate-pairs📝 Commits (2)
2106921fix(input): handle surrogate pairs in stdin buffer923638efix(input): preserve surrogate pairs across chunk boundaries📊 Changes
2 files changed (+48 additions, -3 deletions)
View changed files
📝
packages/core/src/lib/stdin-buffer.test.ts(+29 -0)📝
packages/core/src/lib/stdin-buffer.ts(+19 -3)📄 Description
Bug
extractCompleteSequencesinstdin-buffer.tsiterates the buffer usingremaining[0]andpos++, which operate on UTF-16 code units. But characters above U+FFFF (emoji, CJK Extension B, etc.) are stored as surrogate pairs, two code units.Existing code splits these into two lone surrogates, which
TextEncoder.encode()will then convert to U+FFFD (replacement character) downstream.For example, typing 👍 (U+1F44D) in the input field produces
��instead.Note that this doesn't seem to happen with pasted characters, since they probably go through a different code path. It does happen when I type an emoji using compose key in linux. I suppose it could also happen for other characters like CJK etc...
Fix
Check whether the code unit is a high surrogate (0xD800–0xDBFF) followed by a low surrogate (0xDC00–0xDFFF), and if so keep both as a single sequence entry.
Two regression tests added:
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.