From 6462eecfbd7abc14fa62b33bb079ba424de7d765 Mon Sep 17 00:00:00 2001 From: Bjørn Erik Pedersen Date: Tue, 30 May 2023 11:48:17 +0200 Subject: Avoid panic in invalid language config Fixes #11046 --- hugolib/config_test.go | 56 ++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 45 insertions(+), 11 deletions(-) (limited to 'hugolib') diff --git a/hugolib/config_test.go b/hugolib/config_test.go index edb6b793e..efa2bf6b5 100644 --- a/hugolib/config_test.go +++ b/hugolib/config_test.go @@ -1067,25 +1067,59 @@ LanguageCode: {{ .Site.LanguageCode }}|{{ site.Language.LanguageCode }}| } -// Issue 11047 -func TestConfigYamlNil(t *testing.T) { +func TestConfigMiscPanics(t *testing.T) { t.Parallel() - files := ` + // Issue 11047, + t.Run("empty params", func(t *testing.T) { + + files := ` -- hugo.yaml -- params: -- layouts/index.html -- Foo: {{ site.Params.foo }}| + + + ` + b := NewIntegrationTestBuilder( + IntegrationTestConfig{ + T: t, + TxtarString: files, + }, + ).Build() + + b.AssertFileContent("public/index.html", "Foo: |") + }) + // Issue 11046 + t.Run("invalid language setup", func(t *testing.T) { + + files := ` +-- hugo.toml -- +baseURL = "https://example.org" +languageCode = "en-us" +title = "Blog of me" +defaultContentLanguage = "en" + +[languages] + [en] + lang = "en" + languageName = "English" + weight = 1 +-- layouts/index.html -- +Foo: {{ site.Params.foo }}| -` - b := NewIntegrationTestBuilder( - IntegrationTestConfig{ - T: t, - TxtarString: files, - }, - ).Build() + + ` + b, err := NewIntegrationTestBuilder( + IntegrationTestConfig{ + T: t, + TxtarString: files, + }, + ).BuildE() - b.AssertFileContent("public/index.html", "Foo: |") + b.Assert(err, qt.IsNotNil) + b.Assert(err.Error(), qt.Contains, "no languages") + }) } -- cgit v1.2.3