fix(cli): harden UTF-8 terminal input handling#663
Merged
Conversation
Collaborator
|
Thanks for your contribution! |
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
termios.IUTF8while reading UTF-8 input from a TTYUnicodeDecodeErrorask_userprompts while leaving non-TTY, non-UTF-8, and unsupported platforms unchangedRoot cause
In canonical mode with
IUTF8disabled, erasing a multibyte character may remove only its final byte. For example, typing the three-byte UTF-8 character能and pressing Backspace can leave the incomplete byte sequencee8 83. A strict UTF-8 stdin decoder then raisesUnicodeDecodeError, terminating the chat REPL.Reproduction
stty -iutf8.deeptutor chatwith strict UTF-8 stdin decoding.Tests
IUTF8disabled, enters能, presses Backspace, and verifies both successful input and terminal-mode restorationUnicodeDecodeErrorand verifies the session remains usablepython -m pytest -q tests/cli(41 passed)python -m ruff check deeptutor_cli/chat.py deeptutor_cli/common.py tests/cli/test_chat_cli.py tests/cli/test_chat_terminal.pypython -m ruff format --check deeptutor_cli/chat.py deeptutor_cli/common.py tests/cli/test_chat_cli.py tests/cli/test_chat_terminal.py