Skip to content

Commit

Permalink
Fail on invalid defaultContentLanguage
Browse files Browse the repository at this point in the history
  • Loading branch information
bep committed May 30, 2023
1 parent 12c7517 commit c73e297
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
12 changes: 12 additions & 0 deletions config/allconfig/alldecoders.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,18 @@ var allDecoderSetups = map[string]decodeWeight{
return err
}

// Validate defaultContentLanguage.
var found bool
for lang, _ := range p.c.Languages {
if lang == p.c.DefaultContentLanguage {
found = true
break
}
}
if !found {
return fmt.Errorf("config value %q for defaultContentLanguage does not match any language definition", p.c.DefaultContentLanguage)
}

return nil
},
},
Expand Down
28 changes: 28 additions & 0 deletions hugolib/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1122,4 +1122,32 @@ Foo: {{ site.Params.foo }}|
b.Assert(err.Error(), qt.Contains, "no languages")
})

// Issue 11044
t.Run("invalid defaultContentLanguage", func(t *testing.T) {

files := `
-- hugo.toml --
baseURL = "https://example.org"
defaultContentLanguage = "sv"
[languages]
[languages.en]
languageCode = "en"
languageName = "English"
weight = 1
`
b, err := NewIntegrationTestBuilder(
IntegrationTestConfig{
T: t,
TxtarString: files,
},
).BuildE()

b.Assert(err, qt.IsNotNil)
b.Assert(err.Error(), qt.Contains, "defaultContentLanguage does not match any language definition")
})

}

0 comments on commit c73e297

Please sign in to comment.