diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2023-05-23 17:39:49 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2023-05-23 18:22:24 +0200 |
commit | 120f9dd0c07fa9fab0e70628f28c55ba49f18f84 (patch) | |
tree | 26cc70564eaa21872006d22ac97eb0c05432c552 | |
parent | d666edad71b027e344a255810d1803a054a7bd4d (diff) |
Fix regression when config for OutputFormat.BaseName is an empty stringfix/regression-emptytomlstrins-11000
Fixes #11000
-rw-r--r-- | hugolib/config_test.go | 38 | ||||
-rw-r--r-- | output/config.go | 15 |
2 files changed, 44 insertions, 9 deletions
diff --git a/hugolib/config_test.go b/hugolib/config_test.go index 4af9b7998..2f9c6e3f6 100644 --- a/hugolib/config_test.go +++ b/hugolib/config_test.go @@ -1002,3 +1002,41 @@ Home conf := b.H.Configs.Base b.Assert(conf.IsKindEnabled("term"), qt.Equals, false) } + +// Issue #11000 +func TestConfigEmptyTOMLString(t *testing.T) { + t.Parallel() + + files := ` +-- hugo.toml -- +[mediaTypes] +[mediaTypes."text/htaccess"] +suffixes = ["htaccess"] +[outputFormats] +[outputFormats.htaccess] +mediaType = "text/htaccess" +baseName = "" +isPlainText = false +notAlternative = true +-- content/_index.md -- +--- +outputs: ["html", "htaccess"] +--- +-- layouts/index.html -- +HTML. +-- layouts/_default/list.htaccess -- +HTACCESS. + + + +` + b := NewIntegrationTestBuilder( + IntegrationTestConfig{ + T: t, + TxtarString: files, + }, + ).Build() + + b.AssertFileContent("public/.htaccess", "HTACCESS") + +} diff --git a/output/config.go b/output/config.go index 7b83ef9de..86e5bcfaa 100644 --- a/output/config.go +++ b/output/config.go @@ -32,6 +32,11 @@ type OutputFormatConfig struct { Format } +var defaultOutputFormat = Format{ + BaseName: "index", + Rel: "alternate", +} + func DecodeConfig(mediaTypes media.Types, in any) (*config.ConfigNamespace[map[string]OutputFormatConfig, Formats], error) { buildConfig := func(in any) (Formats, any, error) { f := make(Formats, len(DefaultFormats)) @@ -59,20 +64,12 @@ func DecodeConfig(mediaTypes media.Types, in any) (*config.ConfigNamespace[map[s continue } - var newOutFormat Format + newOutFormat := defaultOutputFormat newOutFormat.Name = k if err := decode(mediaTypes, v, &newOutFormat); err != nil { return f, nil, err } - // We need values for these - if newOutFormat.BaseName == "" { - newOutFormat.BaseName = "index" - } - if newOutFormat.Rel == "" { - newOutFormat.Rel = "alternate" - } - f = append(f, newOutFormat) } |