From 524bf96761886c8750d77b2bb1fc5de1db1670f6 Mon Sep 17 00:00:00 2001 From: Jason Streifling Date: Tue, 5 Mar 2024 17:49:07 +0100 Subject: [PATCH] Added pointer checks to check() functions --- rss.go | 41 ++++++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/rss.go b/rss.go index 82966d1..11bbf9e 100644 --- a/rss.go +++ b/rss.go @@ -142,16 +142,35 @@ func (s *Source) check() error { return nil } +func (c *Content) check() error { + if len(c.Value) == 0 { + return fmt.Errorf("error: value not set") + } + + return nil +} + func (i *Item) check() error { if len(i.Title) == 0 && len(i.Description) == 0 { return fmt.Errorf("error: neither title nor description set") } - if err := i.Enclosure.check(); err != nil { - return fmt.Errorf("error checking enclosure: %v", err) + if i.Enclosure != nil { + if err := i.Enclosure.check(); err != nil { + return fmt.Errorf("error checking enclosure: %v", err) + } } - if err := i.Source.check(); err != nil { - return fmt.Errorf("error checking source: %v", err) + + if i.Source != nil { + if err := i.Source.check(); err != nil { + return fmt.Errorf("error checking source: %v", err) + } + } + + if i.Content != nil { + if err := i.Content.check(); err != nil { + return fmt.Errorf("error checking content: %v", err) + } } return nil @@ -168,11 +187,16 @@ func (c *Channel) check() error { return fmt.Errorf("error: description not set") } - if err := c.Image.check(); err != nil { - return fmt.Errorf("error checking image: %v", err) + if c.Image != nil { + if err := c.Image.check(); err != nil { + return fmt.Errorf("error checking image: %v", err) + } } - if err := c.TextInput.check(); err != nil { - return fmt.Errorf("error checking textInput: %v", err) + + if c.TextInput != nil { + if err := c.TextInput.check(); err != nil { + return fmt.Errorf("error checking textInput: %v", err) + } } for _, item := range c.Items { @@ -188,7 +212,6 @@ func (f *Feed) check() error { if f.Channels == nil { return fmt.Errorf("error: feed has no channels") } - for _, channel := range f.Channels { if err := channel.check(); err != nil { return fmt.Errorf("error checking channel: %v", err)