From 4e8b8700bac43b35072265711f6586c24037157f Mon Sep 17 00:00:00 2001 From: Frank Elsinga Date: Sun, 15 Oct 2023 16:42:20 +0200 Subject: [PATCH] fixed accidentally creating a segfault due to wrong typing --- server/backend/cron/news.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/server/backend/cron/news.go b/server/backend/cron/news.go index 25ae39c3..3641c3d6 100644 --- a/server/backend/cron/news.go +++ b/server/backend/cron/news.go @@ -104,25 +104,26 @@ func (c *CronService) parseNewsFeed(source model.NewsSource) error { } var enclosureUrl = null.StringFrom("") var file *model.File + var fileID null.Int if pickedEnclosure != nil { file, err = c.saveImage(pickedEnclosure.URL) if err != nil { - log.WithError(err).Error("can't save news image") + log.WithError(err).WithField("url", pickedEnclosure.URL).Error("can't save news image") + } else { + fileID = null.IntFrom(file.File) } enclosureUrl = null.StringFrom(pickedEnclosure.URL) } - bm := bluemonday.StrictPolicy() - sanitizedDesc := bm.Sanitize(item.Description) newsItem := model.News{ Date: *item.PublishedParsed, Created: time.Now(), Title: item.Title, - Description: sanitizedDesc, + Description: bluemonday.StrictPolicy().Sanitize(item.Description), Src: source.Source, Link: item.Link, Image: enclosureUrl, - FileID: null.IntFrom(file.File), + FileID: fileID, File: file, } newNews = append(newNews, newsItem)