1
0
mirror of https://github.com/go-gitea/gitea synced 2025-01-08 03:26:07 +01:00

Fix cases.Title crash for concurrency ()

Regression of  and 

Fix 

`cases.Title` is not thread-safe, it has internal state, so it can't be
used as a global shared variable.
This commit is contained in:
wxiaoguang 2023-04-04 06:03:45 +08:00 committed by GitHub
parent cb6ed84c4b
commit 5fc9929da7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -186,19 +186,16 @@ func ToUpperASCII(s string) string {
return string(b)
}
var (
titleCaser = cases.Title(language.English)
titleCaserNoLower = cases.Title(language.English, cases.NoLower)
)
// ToTitleCase returns s with all english words capitalized
func ToTitleCase(s string) string {
return titleCaser.String(s)
// `cases.Title` is not thread-safe, do not use global shared variable for it
return cases.Title(language.English).String(s)
}
// ToTitleCaseNoLower returns s with all english words capitalized without lowercasing
// ToTitleCaseNoLower returns s with all english words capitalized without lower-casing
func ToTitleCaseNoLower(s string) string {
return titleCaserNoLower.String(s)
// `cases.Title` is not thread-safe, do not use global shared variable for it
return cases.Title(language.English, cases.NoLower).String(s)
}
func logError(msg string, args ...any) {