commit 1e9c9d39c8c41f02098471c47242854db99c7165
parent dc184167d3ed9cbfd29fd7b4688462cd58f56159
Author: cblgh <cblgh@cblgh.org>
Date: Mon, 24 Oct 2022 11:49:13 +0200
make util.Capitalize utf-8 safe
Diffstat:
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/util/util.go b/util/util.go
@@ -21,6 +21,7 @@ import (
"github.com/gomarkdown/markdown"
"github.com/komkom/toml"
"github.com/microcosm-cc/bluemonday"
+ "golang.org/x/exp/utf8string"
"cerca/defaults"
"cerca/types"
@@ -152,7 +153,11 @@ func GetURLPortion(req *http.Request, index int) (int, bool) {
}
func Capitalize(s string) string {
- return strings.ToUpper(string(s[0])) + s[1:]
+ // utf8 safe capitalization
+ str := utf8string.NewString(s)
+ first := string(str.At(0))
+ rest := string(str.Slice(1, str.RuneCount()))
+ return strings.ToUpper(first) + rest
}
func CreateIfNotExist(docpath, content string) (bool, error) {