hugolib: Allow nil to be unwrapped as *Page
authorCameron Moore <moorereason@gmail.com>
Wed, 3 Oct 2018 02:46:32 +0000 (21:46 -0500)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Wed, 3 Oct 2018 06:33:42 +0000 (09:33 +0300)
Previously, calls to *Page.Eq(nil) would always return false because the
unwrapPage func didn't support the nil case.  Add support for unwrapping
nil to a *Page.

Fixes #5043

hugolib/site_sections.go
hugolib/site_sections_test.go

index d27b316142ccb645fc0a910994539754fb6b9b46..abcac1d5ce9cd662ae167159c8236fc77a227900 100644 (file)
@@ -152,6 +152,8 @@ func unwrapPage(in interface{}) (*Page, error) {
                return v.Page, nil
        case *PageWithoutContent:
                return v.Page, nil
+       case nil:
+               return nil, nil
        default:
                return nil, fmt.Errorf("%T not supported", in)
        }
index 86ae4080cb92f0b3397f234f17f86af0a0715ec5..24bb6a91f853bd4aecb5e0a9a05c3b4775db59dd 100644 (file)
@@ -166,6 +166,11 @@ PAG|{{ .Title }}|{{ $sect.InSection . }}
                        assert.Equal("empty3.md", b.Pages[0].File.LogicalName())
 
                }},
+               {"empty3", func(p *Page) {
+                       xxx := p.s.getPage(KindPage, "empty3", "nil")
+                       assert.Nil(xxx)
+                       assert.Equal(xxx.Eq(nil), true)
+               }},
                {"top", func(p *Page) {
                        assert.Equal("Tops", p.title)
                        assert.Len(p.Pages, 2)