fix(scanner): replace golang.org/x/text/cases.Title with manual titlecase to prevent panic on Unicode expansion
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.
This commit is contained in:
@@ -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, " ")
|
||||
|
||||
Reference in New Issue
Block a user