mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 08:30:25 +08:00 
			
		
		
		
	Backport #23885 by @wxiaoguang 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. Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
		@@ -185,19 +185,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)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
var (
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user