From b074f6f5a4d427db58a3abdfd58ca255ee4ea496 Mon Sep 17 00:00:00 2001 From: Raphael 'kena' Poss Date: Tue, 27 Sep 2022 17:29:44 +0200 Subject: [PATCH] fix: properly skip over unrecognized CSI sequences. --- key.go | 6 ++++++ key_test.go | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/key.go b/key.go index 8e88c68..dbb608a 100644 --- a/key.go +++ b/key.go @@ -624,6 +624,12 @@ func readInputs(input io.Reader) ([]Msg, error) { continue } + // Is this an unrecognized CSI sequence? If so, ignore it. + if len(runes) > 2 && runes[0] == 0x1b && (runes[1] == '[' || + (len(runes) > 3 && runes[1] == 0x1b && runes[2] == '[')) { + continue + } + // Is the alt key pressed? If so, the buffer will be prefixed with an // escape. alt := false diff --git a/key_test.go b/key_test.go index 869b32f..a73fed8 100644 --- a/key_test.go +++ b/key_test.go @@ -152,6 +152,10 @@ func TestReadInput(t *testing.T) { }, }, }, + "unrecognized": { + []byte{'\x1b', '[', '-', '-', '-', '-', 'X'}, + []Msg{}, + }, } { t.Run(out, func(t *testing.T) { msgs, err := readInputs(bytes.NewReader(td.in))