From 1e531bd31047ccf7225dc8cca7f553a0cf66df23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paulius=20Maru=C5=A1ka?= Date: Fri, 10 Oct 2014 21:35:26 +0300 Subject: [PATCH] Fixes #44, crash when no handlers Recent database handler changes made the library crash, when feed object is created without channel, item handlers (passing nils). These simple changes seem to fix the problem and the library works again. --- feed.go | 8 ++++++-- feed_test.go | 9 +++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/feed.go b/feed.go index 4348e47..51563d8 100644 --- a/feed.go +++ b/feed.go @@ -46,13 +46,17 @@ func (err *UnsupportedFeedError) Error() string { type ChannelHandlerFunc func(f *Feed, newchannels []*Channel) func (h ChannelHandlerFunc) ProcessChannels(f *Feed, newchannels []*Channel) { - h(f, newchannels) + if h != nil { + h(f, newchannels) + } } type ItemHandlerFunc func(f *Feed, ch *Channel, newitems []*Item) func (h ItemHandlerFunc) ProcessItems(f *Feed, ch *Channel, newitems []*Item) { - h(f, ch, newitems) + if h != nil { + h(f, ch, newitems) + } } type Handler interface { diff --git a/feed_test.go b/feed_test.go index 950d8d1..d456b8c 100644 --- a/feed_test.go +++ b/feed_test.go @@ -29,6 +29,15 @@ func TestFeed(t *testing.T) { } } +func Test_NoHandlers(t *testing.T) { + feed := New(1, true, nil, nil) + content, _ := ioutil.ReadFile("testdata/initial.atom") + err := feed.FetchBytes("http://example.com", content, nil) + if err != nil { + t.Error(err) + } +} + func Test_NewItem(t *testing.T) { content, _ := ioutil.ReadFile("testdata/initial.atom") feed := New(1, true, chanHandler, itemHandler)