diff options
author | Bjørn Erik Pedersen <[email protected]> | 2018-11-28 12:36:59 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2018-11-28 12:36:59 +0100 |
commit | b09a40333f382cc1034d2eda856230258ab6b8cc (patch) | |
tree | 8a1da80b3b6a03806f5891f9384d445a6e41d5f2 /hugolib/site_sections.go | |
parent | 7540a62834d4465af8936967e430a9e05a1e1359 (diff) | |
download | hugo-b09a40333f382cc1034d2eda856230258ab6b8cc.tar.gz hugo-b09a40333f382cc1034d2eda856230258ab6b8cc.zip |
hugolib: Improve nil handling in IsDescendant and IsAncestor
Fixes #5461
Diffstat (limited to 'hugolib/site_sections.go')
-rw-r--r-- | hugolib/site_sections.go | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/hugolib/site_sections.go b/hugolib/site_sections.go index abcac1d5c..38f6a3b6f 100644 --- a/hugolib/site_sections.go +++ b/hugolib/site_sections.go @@ -104,8 +104,11 @@ func (p *Page) InSection(other interface{}) (bool, error) { // IsDescendant returns whether the current page is a descendant of the given page. // Note that this method is not relevant for taxonomy lists and taxonomy terms pages. func (p *Page) IsDescendant(other interface{}) (bool, error) { + if p == nil { + return false, nil + } pp, err := unwrapPage(other) - if err != nil { + if err != nil || pp == nil { return false, err } @@ -119,8 +122,12 @@ func (p *Page) IsDescendant(other interface{}) (bool, error) { // IsAncestor returns whether the current page is an ancestor of the given page. // Note that this method is not relevant for taxonomy lists and taxonomy terms pages. func (p *Page) IsAncestor(other interface{}) (bool, error) { + if p == nil { + return false, nil + } + pp, err := unwrapPage(other) - if err != nil { + if err != nil || pp == nil { return false, err } |