Fix regression when config for OutputFormat.BaseName is an empty string

Fixes #11000
This commit is contained in:
Bjørn Erik Pedersen 2023-05-23 17:39:49 +02:00
parent d666edad71
commit ed906a86e2
2 changed files with 44 additions and 9 deletions

View file

@ -1002,3 +1002,41 @@ Home
conf := b.H.Configs.Base conf := b.H.Configs.Base
b.Assert(conf.IsKindEnabled("term"), qt.Equals, false) 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")
}

View file

@ -32,6 +32,11 @@ type OutputFormatConfig struct {
Format Format
} }
var defaultOutputFormat = Format{
BaseName: "index",
Rel: "alternate",
}
func DecodeConfig(mediaTypes media.Types, in any) (*config.ConfigNamespace[map[string]OutputFormatConfig, Formats], error) { func DecodeConfig(mediaTypes media.Types, in any) (*config.ConfigNamespace[map[string]OutputFormatConfig, Formats], error) {
buildConfig := func(in any) (Formats, any, error) { buildConfig := func(in any) (Formats, any, error) {
f := make(Formats, len(DefaultFormats)) f := make(Formats, len(DefaultFormats))
@ -59,20 +64,12 @@ func DecodeConfig(mediaTypes media.Types, in any) (*config.ConfigNamespace[map[s
continue continue
} }
var newOutFormat Format newOutFormat := defaultOutputFormat
newOutFormat.Name = k newOutFormat.Name = k
if err := decode(mediaTypes, v, &newOutFormat); err != nil { if err := decode(mediaTypes, v, &newOutFormat); err != nil {
return f, nil, err 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) f = append(f, newOutFormat)
} }