Skip to content

Commit be93d52

Browse files
committed
tpl: Fix overlapping layout sections
Fixes #13672
1 parent a1cb15e commit be93d52

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

tpl/tplimpl/templatestore.go

+16
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,9 @@ func (ti *TemplInfo) findBestMatchBaseof(s *TemplateStore, d1 TemplateDescriptor
323323
}
324324

325325
ti.baseVariants.WalkPath(k1, func(k2 string, v map[TemplateDescriptor]*TemplWithBaseApplied) (bool, error) {
326+
if !s.inPath(k1, k2) {
327+
return false, nil
328+
}
326329
slashCountK2 := strings.Count(k2, "/")
327330
distance := slashCountK1 - slashCountK2
328331

@@ -615,6 +618,9 @@ func (s *TemplateStore) LookupShortcode(q TemplateQuery) *TemplInfo {
615618
defer s.putBest(best)
616619

617620
s.treeShortcodes.WalkPath(k1, func(k2 string, m map[string]map[TemplateDescriptor]*TemplInfo) (bool, error) {
621+
if !s.inPath(k1, k2) {
622+
return false, nil
623+
}
618624
slashCountK2 := strings.Count(k2, "/")
619625
distance := slashCountK1 - slashCountK2
620626

@@ -780,8 +786,18 @@ func (s *TemplateStore) findBestMatchGet(key string, category Category, consider
780786
}
781787
}
782788

789+
func (s *TemplateStore) inPath(k1, k2 string) bool {
790+
if k1 != k2 && !strings.HasPrefix(k1, k2+"/") {
791+
return false
792+
}
793+
return true
794+
}
795+
783796
func (s *TemplateStore) findBestMatchWalkPath(q TemplateQuery, k1 string, slashCountK1 int, best *bestMatch) {
784797
s.treeMain.WalkPath(k1, func(k2 string, v map[nodeKey]*TemplInfo) (bool, error) {
798+
if !s.inPath(k1, k2) {
799+
return false, nil
800+
}
785801
slashCountK2 := strings.Count(k2, "/")
786802
distance := slashCountK1 - slashCountK2
787803

tpl/tplimpl/templatestore_integration_test.go

+16
Original file line numberDiff line numberDiff line change
@@ -1396,3 +1396,19 @@ layouts/taxononmy.html.html
13961396
b.AssertFileExists("public/p1/index.html", false)
13971397
}
13981398
}
1399+
1400+
func TestTemplateLoopBlogVsBlogrollIssue13672(t *testing.T) {
1401+
t.Parallel()
1402+
files := `
1403+
-- hugo.toml --
1404+
-- layouts/blog/all.html --
1405+
blog/all.html
1406+
-- layouts/blogroll/all.html --
1407+
blogroll/all.html
1408+
-- content/blogroll/p1.md --
1409+
`
1410+
1411+
b := hugolib.Test(t, files)
1412+
1413+
b.AssertFileContent("public/blogroll/p1/index.html", "blogroll/all.html")
1414+
}

0 commit comments

Comments
 (0)