Repository: gohugoio/hugo (language: go)

Issue:
Hugo panics when "disableKinds page" and "defaultContentLanguage custom"
<!--
Please do not use the issue queue for questions or troubleshooting. Unless you are certain that your issue is a software defect, use the forum:

https://discourse.gohugo.io
-->

<!-- Please answer these questions before submitting your issue. Thanks! -->

### What version of Hugo are you using (`hugo version`)?

<pre>
$ hugo version
hugo v0.123.3-a75a659f6fc0cb3a52b2b2ba666a81f79a459376+extended linux/amd64 BuildDate=2024-02-23T17:09:20Z VendorInfo=gohugoio
</pre>

### Does this issue reproduce with the latest release?
<pre>
git clone https://github.com/MarlonLuan/hugo-0.123.x
cd hugo-0.123.x
hugo

</pre>
```shell
Start building sites … 
hugo v0.123.3-a75a659f6fc0cb3a52b2b2ba666a81f79a459376+extended linux/amd64 BuildDate=2024-02-23T17:09:20Z VendorInfo=gohugoio

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x38 pc=0x179bed0]

goroutine 40 [running]:
github.com/gohugoio/hugo/common/paths.(*Path).IsBundle(...)
        /root/project/hugo/common/paths/pathparser.go:533
github.com/gohugoio/hugo/common/paths.(*Path).Base(...)
        /root/project/hugo/common/paths/pathparser.go:461
github.com/gohugoio/hugo/hugolib.(*pageMap).AddFi.func1({0x41043a0, 0xc000329580})
        /root/project/hugo/hugolib/content_map.go:196 +0x1d0
github.com/gohugoio/hugo/hugolib.(*pageMap).AddFi(0xc00094b500, {0x41043a0, 0xc000329580})
        /root/project/hugo/hugolib/content_map.go:218 +0x113
github.com/gohugoio/hugo/hugolib.(*pagesCollector).Collect.func3({0xc000b55f38?, 0xc000b55f18?}, {0x41043a0, 0xc000329580})
        /root/project/hugo/hugolib/pages_capture.go:116 +0x46
github.com/gohugoio/hugo/common/rungroup.Run[...].func1()
        /root/project/hugo/common/rungroup/rungroup.go:64 +0xbd
golang.org/x/sync/errgroup.(*Group).Go.func1()
        /root/project/gomodcache/golang.org/x/sync@v0.6.0/errgroup/errgroup.go:78 +0x56
created by golang.org/x/sync/errgroup.(*Group).Go in goroutine 8
        /root/project/gomodcache/golang.org/x/sync@v0.6.0/errgroup/errgroup.go:75 +0x96
```


Discussion / hints:

Fix patch:
diff --git a/hugolib/content_map.go b/hugolib/content_map.go
index 23b74e1c7fa..0b82bdf28f7 100644
--- a/hugolib/content_map.go
+++ b/hugolib/content_map.go
@@ -193,6 +193,10 @@ func (m *pageMap) AddFi(fi hugofs.FileMetaInfo) error {
 			if err != nil {
 				return err
 			}
+			if pageResource == nil {
+				// Disabled page.
+				return nil
+			}
 			key = pi.Base()
 
 			rs = &resourceSource{r: pageResource}


Test patch:
diff --git a/hugolib/config_test.go b/hugolib/config_test.go
index 0d517896fc7..7914dda45e0 100644
--- a/hugolib/config_test.go
+++ b/hugolib/config_test.go
@@ -1539,3 +1539,22 @@ List.
 	b.AssertLogContains("WARN  DEPRECATED: Kind \"taxonomyterm\" used in disableKinds is deprecated, use \"taxonomy\" instead.\n")
 	b.AssertLogContains("WARN  DEPRECATED: Kind \"taxonomyterm\" used in outputs configuration is deprecated, use \"taxonomy\" instead.\n")
 }
+
+func TestDisableKindsIssue12144(t *testing.T) {
+	files := `
+-- hugo.toml --
+disableKinds = ["page"]
+defaultContentLanguage = "pt-br"
+-- layouts/index.html --
+Home.
+-- content/custom/index.pt-br.md --
+---
+title: "P1 pt"
+---
+-- content/custom/index.en-us.md --
+---
+title: "P1 us"
+---
+`
+	Test(t, files)
+}