summaryrefslogtreecommitdiffstats
path: root/hugolib/page__tree.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2020-03-26 09:41:30 +0100
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2020-03-26 16:11:36 +0100
commit4a39564efe7b02a685598ae9dbae95e2326c0230 (patch)
treed66383a872aabe682f4977137a86b118d9de51d4 /hugolib/page__tree.go
parentb6e097cfe65ecd1d47c805969082e6805563612b (diff)
Fix IsDescendant/IsAncestor for overlapping section names
Fixes #7096
Diffstat (limited to 'hugolib/page__tree.go')
-rw-r--r--hugolib/page__tree.go21
1 files changed, 19 insertions, 2 deletions
diff --git a/hugolib/page__tree.go b/hugolib/page__tree.go
index bd7b586b9..08a4680b7 100644
--- a/hugolib/page__tree.go
+++ b/hugolib/page__tree.go
@@ -37,6 +37,10 @@ func (pt pageTree) IsAncestor(other interface{}) (bool, error) {
ref1, ref2 := pt.p.getTreeRef(), tp.getTreeRef()
+ if ref1 != nil && ref1.key == "/" {
+ return true, nil
+ }
+
if ref1 == nil || ref2 == nil {
if ref1 == nil {
// A 404 or other similar standalone page.
@@ -50,7 +54,12 @@ func (pt pageTree) IsAncestor(other interface{}) (bool, error) {
return false, nil
}
- return strings.HasPrefix(ref2.key, ref1.key), nil
+ if ref2.isSection() {
+ return strings.HasPrefix(ref2.key, ref1.key+"/"), nil
+ }
+
+ return strings.HasPrefix(ref2.key, ref1.key+cmBranchSeparator), nil
+
}
func (pt pageTree) CurrentSection() page.Page {
@@ -75,6 +84,10 @@ func (pt pageTree) IsDescendant(other interface{}) (bool, error) {
ref1, ref2 := pt.p.getTreeRef(), tp.getTreeRef()
+ if ref2 != nil && ref2.key == "/" {
+ return true, nil
+ }
+
if ref1 == nil || ref2 == nil {
if ref2 == nil {
// A 404 or other similar standalone page.
@@ -88,7 +101,11 @@ func (pt pageTree) IsDescendant(other interface{}) (bool, error) {
return false, nil
}
- return strings.HasPrefix(ref1.key, ref2.key), nil
+ if ref1.isSection() {
+ return strings.HasPrefix(ref1.key, ref2.key+"/"), nil
+ }
+
+ return strings.HasPrefix(ref1.key, ref2.key+cmBranchSeparator), nil
}