diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2024-02-01 09:37:05 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2024-02-01 19:42:55 +0100 |
commit | 4174a7866b75c6ae10827cc77dbae0676af8e5eb (patch) | |
tree | 90554344f1749dcdbcfe4587815643c35723b1c2 /common/paths | |
parent | 5dd06b4136aead1d4c8ef835f0670c32ae321152 (diff) |
Fix disabled languages regression
Fixes #11959
Diffstat (limited to 'common/paths')
-rw-r--r-- | common/paths/pathparser.go | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/common/paths/pathparser.go b/common/paths/pathparser.go index 842d9307b..897edb9b7 100644 --- a/common/paths/pathparser.go +++ b/common/paths/pathparser.go @@ -29,6 +29,9 @@ var defaultPathParser PathParser type PathParser struct { // Maps the language code to its index in the languages/sites slice. LanguageIndex map[string]int + + // Reports whether the given language is disabled. + IsLangDisabled func(string) bool } // Parse parses component c with path s into Path using the default path parser. @@ -134,7 +137,16 @@ func (pp *PathParser) doParse(component, s string) (*Path, error) { s := p.s[id.Low:id.High] if hasLang { - if _, found := pp.LanguageIndex[s]; found { + var disabled bool + _, langFound := pp.LanguageIndex[s] + if !langFound { + disabled = pp.IsLangDisabled != nil && pp.IsLangDisabled(s) + if disabled { + p.disabled = true + langFound = true + } + } + if langFound { p.posIdentifierLanguage = 1 p.identifiers = append(p.identifiers, id) } @@ -220,6 +232,7 @@ type Path struct { identifiers []types.LowHigh posIdentifierLanguage int + disabled bool trimLeadingSlash bool @@ -435,6 +448,10 @@ func (p *Path) Identifier(i int) string { return p.identifierAsString(i) } +func (p *Path) Disabled() bool { + return p.disabled +} + func (p *Path) Identifiers() []string { ids := make([]string, len(p.identifiers)) for i, id := range p.identifiers { |