diff options
author | Bjørn Erik Pedersen <[email protected]> | 2022-05-25 18:46:42 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2022-05-28 10:56:54 +0200 |
commit | 3b478f50b7408ad78d085fa6dbc3c7a683c9d943 (patch) | |
tree | 1a2250fc8686beee6ee1d999a0d158f1edbbfe4c /hugolib/page__tree.go | |
parent | f343b8eb7877c857c23dd5f0b554024b7682de3a (diff) | |
download | hugo-3b478f50b7408ad78d085fa6dbc3c7a683c9d943.tar.gz hugo-3b478f50b7408ad78d085fa6dbc3c7a683c9d943.zip |
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
Diffstat (limited to 'hugolib/page__tree.go')
-rw-r--r-- | hugolib/page__tree.go | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/hugolib/page__tree.go b/hugolib/page__tree.go index d2b1f684a..828500e62 100644 --- a/hugolib/page__tree.go +++ b/hugolib/page__tree.go @@ -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 } |