From 77e36b532e52ee974b0cc0213b1de2986bc403a8 Mon Sep 17 00:00:00 2001 From: "Serge A. Zaitsev" Date: Fri, 5 Dec 2014 19:09:10 +0200 Subject: [PATCH] fixed empty header in markdown --- zs.go | 4 +++- zs_test.go | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/zs.go b/zs.go index eb241f3..e9c3b01 100644 --- a/zs.go +++ b/zs.go @@ -32,7 +32,9 @@ func split2(s, delim string) (string, string) { func md(s string) (map[string]string, string) { v := map[string]string{} - // FIXME: if no header? + if strings.Index(s, "\n\n") == -1 { + return map[string]string{}, s + } header, body := split2(s, "\n\n") for _, line := range strings.Split(header, "\n") { key, value := split2(line, ":") diff --git a/zs_test.go b/zs_test.go index b18bfa2..1d3af9e 100644 --- a/zs_test.go +++ b/zs_test.go @@ -46,6 +46,18 @@ this: is a content`) if body != "this: is a content" { t.Error(body) } + + // Test empty md + v, body = md("") + if len(v) != 0 || len(body) != 0 { + t.Error(v, body) + } + + // Test empty header + v, body = md("Hello") + if len(v) != 0 || body != "Hello" { + t.Error(v, body) + } } func TestRender(t *testing.T) {