From 6ad1f41cf47fd4a13251e90b275ea40e4d77ea15 Mon Sep 17 00:00:00 2001 From: Matt Baer Date: Tue, 31 Aug 2021 11:18:58 -0400 Subject: [PATCH] Prevent crash on empty title This title, typed directly in the plain editor, would previously crash the app / show the user a "server error": # # --- postrender.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/postrender.go b/postrender.go index 13bf02e..b200a59 100644 --- a/postrender.go +++ b/postrender.go @@ -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

+ if len(md) == 0 { + return "" + } md = md[len("

") : len(md)-len("

")] // Strip out bad HTML policy := bluemonday.UGCPolicy()