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.
Fix: Random Character Input from Terminal Escape Sequences
Issue Description
Random characters were being input to k9s after periods of inactivity. The issue was observed on both Linux and Mac, across different terminal emulators. Users reported seeing strings like
1212/1212/1212\[7;15Rappearing in the command prompt without any user input.Symptoms:
Example of problematic input:
The string
\[7;15Ris a terminal escape sequence (cursor position report) that was being interpreted as user input.Root Cause
The prompt handler in
internal/ui/prompt.gowas accepting alltcell.KeyRuneevents without validating that the runes were valid user input. Terminal escape sequences, particularly cursor position reports and other control sequences, were being misinterpreted as keyboard input by tcell and passed through to the command buffer.The issue occurred because:
KeyRuneevents without filteringSolution
Added input validation to filter out control characters and non-printable runes before they're added to the command buffer.
Changes Made
File:
internal/ui/prompt.gounicodeimport for character validationisValidInputRune()helper function that:KeyRunecase in thekeyboard()handler to validate runes before adding them to the bufferCode Changes
Testing
Unit Tests
Added comprehensive unit tests in
internal/ui/prompt_validation_test.go:TestPrompt_FiltersControlCharacters- Verifies control characters (NULL, ESC, DEL, etc.) are filteredTestPrompt_AcceptsPrintableCharacters- Verifies valid printable characters are acceptedTestPrompt_FiltersEscapeSequencePattern- Verifies escape sequence patterns don't introduce control charactersAll tests pass successfully.
Manual Testing
make build./execs/k9sImpact
Related