Skip to content

Commit 9877c08

Browse files
committed
Skip parsing empty key specs
1 parent 7ec8452 commit 9877c08

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

internal/ui/components/keyboard.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ import (
1515

1616
// keyMatch checks if an event matches a key specification string.
1717
func keyMatch(ev *tcell.EventKey, spec string) bool {
18+
if strings.TrimSpace(spec) == "" {
19+
return false
20+
}
21+
1822
key, r, mod, err := keys.Parse(spec)
1923
if err != nil {
2024
if config.DebugEnabled {
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package components
2+
3+
import (
4+
"testing"
5+
6+
"github.com/gdamore/tcell/v2"
7+
)
8+
9+
func TestKeyMatchEmptySpecReturnsFalse(t *testing.T) {
10+
ev := tcell.NewEventKey(tcell.KeyRune, 'x', tcell.ModNone)
11+
12+
if keyMatch(ev, "") {
13+
t.Fatal("expected empty key spec to never match")
14+
}
15+
16+
if keyMatch(ev, " ") {
17+
t.Fatal("expected whitespace-only key spec to never match")
18+
}
19+
}

0 commit comments

Comments
 (0)