Fix crashes for 404 in IsAncestor etc.

Fixes #6931
This commit is contained in:
Bjørn Erik Pedersen
2020-02-22 10:57:43 +01:00
parent c1eb625124
commit a524124beb
4 changed files with 64 additions and 6 deletions

View File

@@ -37,6 +37,15 @@ func (pt pageTree) IsAncestor(other interface{}) (bool, error) {
ref1, ref2 := pt.p.getTreeRef(), tp.getTreeRef()
if ref1 == nil || ref2 == nil {
if ref1 == nil {
// A 404 or other similar standalone page.
return false, nil
}
return ref1.n.p.IsHome(), nil
}
if !ref1.isSection() {
return false, nil
}
@@ -66,6 +75,15 @@ func (pt pageTree) IsDescendant(other interface{}) (bool, error) {
ref1, ref2 := pt.p.getTreeRef(), tp.getTreeRef()
if ref1 == nil || ref2 == nil {
if ref2 == nil {
// A 404 or other similar standalone page.
return false, nil
}
return ref2.n.p.IsHome(), nil
}
if !ref2.isSection() {
return false, nil
}
@@ -76,6 +94,9 @@ func (pt pageTree) IsDescendant(other interface{}) (bool, error) {
func (pt pageTree) FirstSection() page.Page {
ref := pt.p.getTreeRef()
if ref == nil {
return pt.p.s.home
}
key := ref.key
if !ref.isSection() {
key = path.Dir(key)
@@ -99,6 +120,14 @@ func (pt pageTree) InSection(other interface{}) (bool, error) {
ref1, ref2 := pt.p.getTreeRef(), tp.getTreeRef()
if ref1 == nil || ref2 == nil {
if ref1 == nil {
// A 404 or other similar standalone page.
return false, nil
}
return ref1.n.p.IsHome(), nil
}
s1, _ := ref1.getCurrentSection()
s2, _ := ref2.getCurrentSection()
@@ -123,7 +152,7 @@ func (pt pageTree) Parent() page.Page {
tree := p.getTreeRef()
if pt.p.Kind() == page.KindTaxonomyTerm || tree == nil {
if tree == nil || pt.p.Kind() == page.KindTaxonomyTerm {
return pt.p.s.home
}