diff --git a/parser/frontmatter.go b/parser/frontmatter.go index 881fb94..1bf1151 100644 --- a/parser/frontmatter.go +++ b/parser/frontmatter.go @@ -54,7 +54,7 @@ func ParseKeyValueLine(line string) (string, string, error) { // delimiterRegex denotes the regex for a line that matches on when the // FrontMatter section is delimited from the rest of the content. // It must be a minimum of 3 dashes (-), and no other content. -var delimiterRegex = regexp.MustCompile("$-{3,}^") +var delimiterRegex = regexp.MustCompile("^-{3,}$") // ExtractFrontMatter will take an entire MarkDown file, and return a map that // contains key-value pairs. The key-value pairs must end with an extra line diff --git a/parser/frontmatter_test.go b/parser/frontmatter_test.go index be9c73e..209a5f3 100644 --- a/parser/frontmatter_test.go +++ b/parser/frontmatter_test.go @@ -87,6 +87,13 @@ func TestExtractFrontMatterWithValidContent(t *testing.T) { "parsing empty input yields unexpected result", ) + fm, e = parser.ExtractFrontMatter([]string{"# Content", "..."}) + asrt.EqualValues( + extractResult{map[string]string{}, nil}, + extractResult{fm, e}, + "parsing empty input yields unexpected result", + ) + fm, e = parser.ExtractFrontMatter([]string{"Key: Value", "---"}) asrt.EqualValues( extractResult{map[string]string{"Key": "Value"}, nil}, @@ -133,11 +140,11 @@ func TestExtractFrontMatterWithBadKeys(t *testing.T) { "parsing invalid FrontMatter with blank key yields invalid result", ) - fm, e = parser.ExtractFrontMatter([]string{"Key: Value", "Key: Dupe Value"}) + fm, e = parser.ExtractFrontMatter([]string{"Key: Value", "Key: Dupe Value", "---"}) asrt.EqualValues( extractResult{map[string]string{"Key": "Value"}, fmt.Errorf("error on parsing line 2: %w", parser.ErrDuplicateKey)}, extractResult{fm, e}, - "parsing invalid FrontMatter with no final dashes yields invalid result", + "parsing invalid FrontMatter with duplicate key entry yields invalid result", ) fm, e = parser.ExtractFrontMatter([]string{"Key: Value", "Another Key: Another Value"})