summaryrefslogtreecommitdiffstats
path: root/hugolib
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2025-01-09 06:01:58 +0100
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2025-01-09 08:00:30 +0100
commitc5a63a3b4f68b829c73365b6344e502f1a237eae (patch)
treedfaca2657a5bd63e40ad87af85c26cf5e15d1994 /hugolib
parent61d3d20129e69be6730132b9ada5f8128d9f7233 (diff)
downloadhugo-c5a63a3b4f68b829c73365b6344e502f1a237eae.tar.gz
hugo-c5a63a3b4f68b829c73365b6344e502f1a237eae.zip
Fix branch resource overlapping bundle path
Fixes #13228
Diffstat (limited to 'hugolib')
-rw-r--r--hugolib/content_map_page.go19
-rw-r--r--hugolib/content_map_test.go29
2 files changed, 46 insertions, 2 deletions
diff --git a/hugolib/content_map_page.go b/hugolib/content_map_page.go
index b369dfe13..b48504203 100644
--- a/hugolib/content_map_page.go
+++ b/hugolib/content_map_page.go
@@ -509,8 +509,23 @@ func (m *pageMap) forEachResourceInPage(
// A page key points to the logical path of a page, which when sourced from the filesystem
// may represent a directory (bundles) or a single content file (e.g. p1.md).
// So, to avoid any overlapping ambiguity, we start looking from the owning directory.
- ownerKey, _ := m.treePages.LongestPrefixAll(path.Dir(resourceKey))
- if ownerKey != keyPage {
+ s := resourceKey
+
+ for {
+ s = path.Dir(s)
+ ownerKey, found := m.treePages.LongestPrefixAll(s)
+ if !found {
+ return true, nil
+ }
+ if ownerKey == keyPage {
+ break
+ }
+
+ if s != ownerKey && strings.HasPrefix(s, ownerKey) {
+ // Keep looking
+ continue
+ }
+
// Stop walking downwards, someone else owns this resource.
rw.SkipPrefix(ownerKey + "/")
return false, nil
diff --git a/hugolib/content_map_test.go b/hugolib/content_map_test.go
index a9f719f4a..6a1245846 100644
--- a/hugolib/content_map_test.go
+++ b/hugolib/content_map_test.go
@@ -361,6 +361,35 @@ p1-foo.txt
b.AssertFileExists("public/s1/p1/index.html", true)
}
+// Issue 13228.
+func TestBranchResourceOverlap(t *testing.T) {
+ t.Parallel()
+
+ files := `
+-- hugo.toml --
+disableKinds = ['page','rss','section','sitemap','taxonomy','term']
+-- content/_index.md --
+---
+title: home
+---
+-- content/s1/_index.md --
+---
+title: s1
+---
+-- content/s1x/a.txt --
+a.txt
+-- layouts/index.html --
+Home.
+{{ range .Resources.Match "**" }}
+ {{ .Name }}|
+{{ end }}
+`
+
+ b := Test(t, files)
+
+ b.AssertFileContent("public/index.html", "s1x/a.txt|")
+}
+
func TestSitemapOverrideFilename(t *testing.T) {
t.Parallel()