diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2023-04-04 06:03:45 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-03 18:03:45 -0400 |
commit | 5fc9929da7ca3e362506c8624bcfde4970141a5d (patch) | |
tree | ac9c1e26adf5308e2b918349b17d4c3c71d3cd56 /modules/util | |
parent | cb6ed84c4be5256badf5e99537ca304e2884a26e (diff) | |
download | gitea-5fc9929da7ca3e362506c8624bcfde4970141a5d.tar.gz gitea-5fc9929da7ca3e362506c8624bcfde4970141a5d.zip |
Fix `cases.Title` crash for concurrency (#23885)
Regression of #19676 and #21814
Fix #23872
`cases.Title` is not thread-safe, it has internal state, so it can't be
used as a global shared variable.
Diffstat (limited to 'modules/util')
-rw-r--r-- | modules/util/util.go | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/modules/util/util.go b/modules/util/util.go index 9c7097ad34..e9ea007ccb 100644 --- a/modules/util/util.go +++ b/modules/util/util.go @@ -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) { |