From 453d3eb567fba86f3d7fb5104d51acf5e350bde4 Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Sat, 25 Jul 2015 15:47:33 -0600 Subject: [PATCH] markdown: Fix when md file has front matter but empty body --- middleware/markdown/metadata.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/middleware/markdown/metadata.go b/middleware/markdown/metadata.go index eaf08b95..1420f97b 100644 --- a/middleware/markdown/metadata.go +++ b/middleware/markdown/metadata.go @@ -207,11 +207,7 @@ func extractMetadata(parser MetadataParser, b []byte) (metadata []byte, markdown // Read remaining lines until closing identifier is found for { line, err := reader.ReadBytes('\n') - if err != nil { - if err == io.EOF { - // no closing metadata identifier found - return nil, nil, fmt.Errorf("metadata not closed ('%s' not found)", parser.Closing()) - } + if err != nil && err != io.EOF { return nil, nil, err } @@ -220,6 +216,11 @@ func extractMetadata(parser MetadataParser, b []byte) (metadata []byte, markdown break } + // if file ended, by this point no closing identifier was found + if err == io.EOF { + return nil, nil, fmt.Errorf("metadata not closed ('%s' not found)", parser.Closing()) + } + metaBuf.Write(line) metaBuf.WriteString("\r\n") }