Prevent crash on empty title

This title, typed directly in the plain editor, would previously crash
the app / show the user a "server error":

# #
This commit is contained in:
Matt Baer 2021-08-31 11:18:58 -04:00
parent 3270470b68
commit 6ad1f41cf4

View file

@ -201,6 +201,9 @@ func applyBasicMarkdown(data []byte) string {
md := blackfriday.Markdown(append([]byte("# "), data...), blackfriday.HtmlRenderer(htmlFlags, "", ""), mdExtensions)
// Remove H1 markup
md = bytes.TrimSpace(md) // blackfriday.Markdown adds a newline at the end of the <h1>
if len(md) == 0 {
return ""
}
md = md[len("<h1>") : len(md)-len("</h1>")]
// Strip out bad HTML
policy := bluemonday.UGCPolicy()