From 6070a3b7cc8ea13d58e4b682c4ee975d7aad42ef Mon Sep 17 00:00:00 2001 From: James Houlahan Date: Wed, 3 Jun 2020 14:05:20 +0200 Subject: [PATCH] fix: crash if fail to find necessary html element --- Changelog.md | 1 + pkg/message/html.go | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/Changelog.md b/Changelog.md index 1534b7af..135e63bd 100644 --- a/Changelog.md +++ b/Changelog.md @@ -22,6 +22,7 @@ Changelog [format](http://keepachangelog.com/en/1.0.0/) * GODT-363 Drafts are not deleted when already created on webapp. * GODT-390 Don't logout user if AuthRefresh fails because internet was off * GODT-341 Fixed flaky unittest for Store synchronization cooldown +* Crash when failing to match necessary html element ## [v1.2.7] Donghai-hotfix - beta (2020-05-07) diff --git a/pkg/message/html.go b/pkg/message/html.go index 9e3cea7e..163a2ea8 100644 --- a/pkg/message/html.go +++ b/pkg/message/html.go @@ -19,6 +19,7 @@ package message import ( "bytes" + "errors" escape "html" "strings" @@ -40,6 +41,10 @@ func stripHTML(input string) (stripped string, err error) { reader := strings.NewReader(input) doc, _ := html.Parse(reader) body := cascadia.MustCompile("body").MatchFirst(doc) + if body == nil { + err = errors.New("failed to find necessary html element") + return + } var buf1 bytes.Buffer if err = html.Render(&buf1, body); err != nil { stripped = input