fix: frontmatter delimiter regex swapped start-ending character

master
ALI Hamza 2020-11-27 21:56:31 +07:00
parent 400eae9000
commit fccb62accd
Signed by: hamza
GPG Key ID: 22473A32291F8CB6
2 changed files with 10 additions and 3 deletions

@ -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

@ -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"})