From d37ab544e814b663bede266fa9ae83adf5e67d81 Mon Sep 17 00:00:00 2001 From: Matt Baer Date: Fri, 25 Jun 2021 17:07:42 -0400 Subject: [PATCH] Prevent out of bounds error on title with only whitespace --- postrender.go | 2 +- postrender_test.go | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/postrender.go b/postrender.go index 1cb4f0e..369ce51 100644 --- a/postrender.go +++ b/postrender.go @@ -182,7 +182,7 @@ func applyMarkdownSpecial(data []byte, skipNoFollow bool, baseURL string, cfg *c } func applyBasicMarkdown(data []byte) string { - if len(data) == 0 { + if len(bytes.TrimSpace(data)) == 0 { return "" } diff --git a/postrender_test.go b/postrender_test.go index 262d550..531c0f1 100644 --- a/postrender_test.go +++ b/postrender_test.go @@ -19,6 +19,12 @@ func TestApplyBasicMarkdown(t *testing.T) { result string }{ {"empty", "", ""}, + {"empty spaces", " ", ""}, + {"empty tabs", "\t", ""}, + {"empty newline", "\n", ""}, + {"nums", "123", "123"}, + {"dot", ".", "."}, + {"dash", "-", "-"}, {"plain", "Hello, World!", "Hello, World!"}, {"multibyte", "こんにちは", `こんにちは`}, {"bold", "**안녕하세요**", `안녕하세요`},