From 0af2ee49513dc26754b82c6be47fe77b41b49a63 Mon Sep 17 00:00:00 2001 From: John O'Keefe Date: Wed, 27 May 2026 11:10:28 -0400 Subject: [PATCH] fix(scanner): replace golang.org/x/text/cases.Title with manual titlecase to prevent panic on Unicode expansion MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The cases.Title caser panicked with 'slice bounds out of range' when processing certain Unicode characters that expand during case transformation (e.g. ß → SS). This panic crashed the entire server during scanning, causing WebSocket disconnections and failed scan requests. --- internal/utils/tags.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/internal/utils/tags.go b/internal/utils/tags.go index 216481d..9e2235f 100644 --- a/internal/utils/tags.go +++ b/internal/utils/tags.go @@ -4,14 +4,8 @@ import ( "sort" "strings" "unicode" - - "golang.org/x/text/cases" - "golang.org/x/text/language" ) -// titleCaser is a global caser for titlecase conversion -var titleCaser = cases.Title(language.Und) - // titlecase converts a string to title case while preserving hyphenation and apostrophes // Example: "science fiction" → "Science Fiction", "non-fiction" → "Non-Fiction", "o'reilly" → "O'Reilly" func titlecase(s string) string { @@ -34,7 +28,12 @@ func titlecase(s string) string { } words[i] = result.String() } else { - words[i] = titleCaser.String(word) + runes := []rune(word) + runes[0] = unicode.ToUpper(runes[0]) + for j := 1; j < len(runes); j++ { + runes[j] = unicode.ToLower(runes[j]) + } + words[i] = string(runes) } } return strings.Join(words, " ")