From 2ea7ccc4047d86c3e4386a33f02b1b68a26668ac Mon Sep 17 00:00:00 2001 From: Lucas de Castro Zanoni Date: Mon, 9 Feb 2026 19:41:01 -0300 Subject: [PATCH] fix: sanitize filter targets to prevent fuzzy search panic on binary data The sahilm/fuzzy library panics with 'index out of range' when the fuzzy matching algorithm encounters clipboard entries containing non-printable or binary data from copied images. This causes the TUI to crash when typing certain characters as the first filter character. Strip non-printable characters from filter targets before passing to the fuzzy search. This preserves full fuzzy matching behavior on the printable text content. Fixes #148 --- app/model.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/app/model.go b/app/model.go index 777c1ae..bd1471b 100644 --- a/app/model.go +++ b/app/model.go @@ -2,7 +2,9 @@ package app import ( "fmt" + "strings" "time" + "unicode" "github.com/charmbracelet/bubbles/help" "github.com/charmbracelet/bubbles/key" @@ -95,6 +97,7 @@ func NewModel() Model { del := m.newItemDelegate() clipboardList := list.New(entryItems, del, 0, 0) + clipboardList.Filter = sanitizedFilter clipboardList.KeyMap = defaultOverrides(config.ClipseConfig.KeyBindings) // override default list keys with custom values clipboardList.Title = clipboardTitle // set hardcoded title clipboardList.SetShowHelp(false) // override with custom @@ -127,6 +130,23 @@ func NewModel() Model { return m } +func sanitizedFilter(term string, targets []string) []list.Rank { + sanitized := make([]string, len(targets)) + for i, t := range targets { + sanitized[i] = stripNonPrintable(t) + } + return list.DefaultFilter(term, sanitized) +} + +func stripNonPrintable(s string) string { + return strings.Map(func(r rune) rune { + if unicode.IsPrint(r) { + return r + } + return -1 + }, s) +} + // if isPinned is true, returns only an array of pinned items, otherwise all func filterItems(clipboardItems []config.ClipboardItem, isPinned bool) []list.Item { var filteredItems []list.Item