mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-27 22:09:53 +02:00
Fix HasMenuCurrent and IsDescendant/IsAncestor when comparing to itself
There may be sites in the wild that depends on the faulty behaviour of IsDescendant/IsAncestor when comparing to itself, but * The documentation and common sense says that a thing cannot be descendant or ancestor to itself. * The bug introduced in `HasMenuCurrent` comes directly from that confusion. Fixes #9846
This commit is contained in:
@@ -36,6 +36,9 @@ func (pt pageTree) IsAncestor(other any) (bool, error) {
|
||||
}
|
||||
|
||||
ref1, ref2 := pt.p.getTreeRef(), tp.getTreeRef()
|
||||
if ref1 != nil && ref2 != nil && ref1.key == ref2.key {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
if ref1 != nil && ref1.key == "/" {
|
||||
return true, nil
|
||||
@@ -50,10 +53,6 @@ func (pt pageTree) IsAncestor(other any) (bool, error) {
|
||||
return ref1.n.p.IsHome(), nil
|
||||
}
|
||||
|
||||
if ref1.key == ref2.key {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
if strings.HasPrefix(ref2.key, ref1.key) {
|
||||
return true, nil
|
||||
}
|
||||
@@ -82,6 +81,9 @@ func (pt pageTree) IsDescendant(other any) (bool, error) {
|
||||
}
|
||||
|
||||
ref1, ref2 := pt.p.getTreeRef(), tp.getTreeRef()
|
||||
if ref1 != nil && ref2 != nil && ref1.key == ref2.key {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
if ref2 != nil && ref2.key == "/" {
|
||||
return true, nil
|
||||
@@ -96,10 +98,6 @@ func (pt pageTree) IsDescendant(other any) (bool, error) {
|
||||
return ref2.n.p.IsHome(), nil
|
||||
}
|
||||
|
||||
if ref1.key == ref2.key {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
if strings.HasPrefix(ref1.key, ref2.key) {
|
||||
return true, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user