Skip to content

Commit 7f82b41

Browse files
committed
parser: Final (!) fix for issue with escaped JSON front matter
Fixes #3682
1 parent 84db6c7 commit 7f82b41

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

‎parser/page.go‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,6 @@ func extractFrontMatterDelims(r *bufio.Reader, left, right []byte) (fm []byte, e
337337
if escapeState != 1 {
338338
inQuote = !inQuote
339339
}
340-
escapeState = 0
341340
case '\\':
342341
escapeState++
343342
case left[len(left)-1]:
@@ -403,6 +402,10 @@ func extractFrontMatterDelims(r *bufio.Reader, left, right []byte) (fm []byte, e
403402
return buf.Bytes(), nil
404403
}
405404

405+
if c != '\\' {
406+
escapeState = 0
407+
}
408+
406409
}
407410
}
408411

‎parser/parse_frontmatter_test.go‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,8 @@ func TestExtractFrontMatterDelim(t *testing.T) {
305305
{`{ "title": "\"Foo\"" }`, `{ "title": "\"Foo\"" }`, noErrExpected},
306306
{`{ "title": "\"Foo\"\"" }`, `{ "title": "\"Foo\"\"" }`, noErrExpected},
307307
{`{ "url": "http:\/\/example.com\/play\/url?id=1" }`, `{ "url": "http:\/\/example.com\/play\/url?id=1" }`, noErrExpected},
308+
{`{ "test": "\"New\r\nString\"" }`, `{ "test": "\"New\r\nString\"" }`, noErrExpected},
309+
{`{ "test": "RTS\/RPG" }`, `{ "test": "RTS\/RPG" }`, noErrExpected},
308310
}
309311

310312
for i, test := range tests {

0 commit comments

Comments
 (0)