fix: crash if fail to find necessary html element

This commit is contained in:
James Houlahan
2020-06-03 14:05:20 +02:00
parent 9e633400b0
commit 6070a3b7cc
2 changed files with 6 additions and 0 deletions

View File

@ -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)

View File

@ -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