Permalink
Browse files

parser: Final (!) fix for issue with escaped JSON front matter

Fixes #3682
  • Loading branch information...
bep committed Jul 8, 2017
1 parent 84db6c7 commit 7f82b41a24af0fd04d28fbfebf9254766a3c6e6f
Showing with 6 additions and 1 deletion.
  1. +4 −1 parser/page.go
  2. +2 −0 parser/parse_frontmatter_test.go
View
@@ -337,7 +337,6 @@ func extractFrontMatterDelims(r *bufio.Reader, left, right []byte) (fm []byte, e
if escapeState != 1 {
inQuote = !inQuote
}
escapeState = 0
case '\\':
escapeState++
case left[len(left)-1]:
@@ -403,6 +402,10 @@ func extractFrontMatterDelims(r *bufio.Reader, left, right []byte) (fm []byte, e
return buf.Bytes(), nil
}
if c != '\\' {
escapeState = 0
}
}
}
@@ -305,6 +305,8 @@ func TestExtractFrontMatterDelim(t *testing.T) {
{`{ "title": "\"Foo\"" }`, `{ "title": "\"Foo\"" }`, noErrExpected},
{`{ "title": "\"Foo\"\"" }`, `{ "title": "\"Foo\"\"" }`, noErrExpected},
{`{ "url": "http:\/\/example.com\/play\/url?id=1" }`, `{ "url": "http:\/\/example.com\/play\/url?id=1" }`, noErrExpected},
{`{ "test": "\"New\r\nString\"" }`, `{ "test": "\"New\r\nString\"" }`, noErrExpected},
{`{ "test": "RTS\/RPG" }`, `{ "test": "RTS\/RPG" }`, noErrExpected},
}
for i, test := range tests {

0 comments on commit 7f82b41

Please sign in to comment.