ref: 98659bf3b8d11a6bd57439d70551f5f018b6a404
parent: 4bed69629e55f7292505a74e8437a5a05ddf9a22
author: Tatsushi Demachi <[email protected]>
date: Mon Aug 3 19:32:51 EDT 2015
Fix searching YAML/TOML delimiters in frontmatter When a YAML/TOML's delimiter character sequence is included in a frontmatter string, parser mistakes it as a delimiter. This fixes it by checking a character right before the delimiter sequence is '\n' or it is the beginning of the frontmatter. Fix #1320
--- a/parser/page.go
+++ b/parser/page.go
@@ -207,7 +207,7 @@
switch c {
case left[len(left)-1]:
if sameDelim { // YAML, TOML case
- if bytes.HasSuffix(buf.Bytes(), left) {
+ if bytes.HasSuffix(buf.Bytes(), left) && (buf.Len() == len(left) || buf.Bytes()[buf.Len()-len(left)-1] == '\n') {
nextByte:
c, err = r.ReadByte()
if err != nil {
--- a/parser/parse_frontmatter_test.go
+++ b/parser/parse_frontmatter_test.go
@@ -238,6 +238,7 @@
{"--- \nminc\n--- \ncontent", []byte("---\nminc\n---\n"), true},
{"---\ncnim\n---\ncontent\n", []byte("---\ncnim\n---\n"), true},
{"---\ntitle: slug doc 2\nslug: slug-doc-2\n---\ncontent\n", []byte("---\ntitle: slug doc 2\nslug: slug-doc-2\n---\n"), true},
+ {"---\npermalink: '/blog/title---subtitle.html'\n---\ncontent\n", []byte("---\npermalink: '/blog/title---subtitle.html'\n---\n"), true},
}
for _, test := range tests {