From f1ba7b3153bd555cb213ba17a1d31168bf8584b7 Mon Sep 17 00:00:00 2001 From: John Wang Date: Fri, 22 Nov 2024 19:59:15 -0800 Subject: [PATCH] fix: `type/stringsutil`: fix `ToUpperFirst()` for zero length input --- type/stringsutil/stringsutil.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/type/stringsutil/stringsutil.go b/type/stringsutil/stringsutil.go index 91d60990..ec64a32b 100644 --- a/type/stringsutil/stringsutil.go +++ b/type/stringsutil/stringsutil.go @@ -82,7 +82,9 @@ func ToUpperFirst(s1 string, lowerRest bool) string { s1 = strings.ToLower(s1) } a1 := []rune(s1) - a1[0] = unicode.ToUpper(a1[0]) + if len(a1) > 0 { + a1[0] = unicode.ToUpper(a1[0]) + } return string(a1) }