diff options
author | Bjørn Erik Pedersen <[email protected]> | 2023-05-29 12:58:22 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2023-05-29 14:01:07 +0200 |
commit | 32585696be70dba987dbad299b22a05f9a820a49 (patch) | |
tree | 202537f9e982084a2f22c8452c7fd39374f9c8a5 /langs | |
parent | d47225ce9ef1a1ae31d89e8aed07a6fcc9d524f2 (diff) | |
download | hugo-32585696be70dba987dbad299b22a05f9a820a49.tar.gz hugo-32585696be70dba987dbad299b22a05f9a820a49.zip |
Fix potential deadlock in ByParam
Fixes #11039
Diffstat (limited to 'langs')
-rw-r--r-- | langs/language.go | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/langs/language.go b/langs/language.go index 4e089606c..f8d4f64b5 100644 --- a/langs/language.go +++ b/langs/language.go @@ -41,8 +41,11 @@ type Language struct { translator locales.Translator timeFormatter htime.TimeFormatter tag language.Tag - collator *Collator - location *time.Location + // collator1 and collator2 are the same, we have 2 to prevent deadlocks. + collator1 *Collator + collator2 *Collator + + location *time.Location // This is just an alias of Site.Params. params maps.Params @@ -58,14 +61,20 @@ func NewLanguage(lang, defaultContentLanguage, timeZone string, languageConfig L } } - var coll *Collator + var coll1, coll2 *Collator tag, err := language.Parse(lang) if err == nil { - coll = &Collator{ + coll1 = &Collator{ + c: collate.New(tag), + } + coll2 = &Collator{ c: collate.New(tag), } } else { - coll = &Collator{ + coll1 = &Collator{ + c: collate.New(language.English), + } + coll2 = &Collator{ c: collate.New(language.English), } } @@ -76,7 +85,8 @@ func NewLanguage(lang, defaultContentLanguage, timeZone string, languageConfig L translator: translator, timeFormatter: htime.NewTimeFormatter(translator), tag: tag, - collator: coll, + collator1: coll1, + collator2: coll2, } return l, l.loadLocation(timeZone) @@ -165,8 +175,12 @@ func GetLocation(l *Language) *time.Location { return l.location } -func GetCollator(l *Language) *Collator { - return l.collator +func GetCollator1(l *Language) *Collator { + return l.collator1 +} + +func GetCollator2(l *Language) *Collator { + return l.collator2 } type Collator struct { |