Skip to content

Commit

Permalink
Fix regression when config for OutputFormat.BaseName is an empty string
Browse files Browse the repository at this point in the history
Fixes #11000
  • Loading branch information
bep committed May 23, 2023
1 parent d666eda commit ed906a8
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 9 deletions.
38 changes: 38 additions & 0 deletions hugolib/config_test.go
Expand Up @@ -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")

}
15 changes: 6 additions & 9 deletions output/config.go
Expand Up @@ -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))
Expand Down Expand Up @@ -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)

}
Expand Down

0 comments on commit ed906a8

Please sign in to comment.