]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
Fix regression when config for OutputFormat.BaseName is an empty string
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Tue, 23 May 2023 15:39:49 +0000 (17:39 +0200)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Tue, 23 May 2023 17:23:39 +0000 (19:23 +0200)
Fixes #11000

hugolib/config_test.go
output/config.go

index 4af9b7998c4c00cd86b06debd2a85b50fee170b9..2f9c6e3f6788d728b2b2eb80a9fafcbcbff5c06d 100644 (file)
@@ -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")
+
+}
index 7b83ef9de9431ffdfd2a696226e7b3264f5f4010..86e5bcfaaf39fab2a4492b820287363588099245 100644 (file)
@@ -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)
 
                        }