Skip to content

Commit

Permalink
parser: Final (!) fix for issue with escaped JSON front matter
Browse files Browse the repository at this point in the history
Fixes #3682
  • Loading branch information
bep committed Jul 8, 2017
1 parent 84db6c7 commit 7f82b41
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 4 additions & 1 deletion parser/page.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down Expand Up @@ -403,6 +402,10 @@ func extractFrontMatterDelims(r *bufio.Reader, left, right []byte) (fm []byte, e
return buf.Bytes(), nil
}

if c != '\\' {
escapeState = 0
}

}
}

Expand Down
2 changes: 2 additions & 0 deletions parser/parse_frontmatter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 7f82b41

Please sign in to comment.