1
0
mirror of https://github.com/gohugoio/hugo.git synced 2024-05-11 05:54:58 +00:00

parser: Fix handling of JSON front matter with escaped quotes

Fixes #3661
This commit is contained in:
Bjørn Erik Pedersen
2017-07-03 09:00:17 +02:00
parent 34c566773a
commit e10e51a008
2 changed files with 14 additions and 2 deletions

View File

@@ -305,6 +305,7 @@ func extractFrontMatterDelims(r *bufio.Reader, left, right []byte) (fm []byte, e
level int
sameDelim = bytes.Equal(left, right)
inQuote bool
escaped bool
)
// Frontmatter must start with a delimiter. To check it first,
// pre-reads beginning delimiter length - 1 bytes from Reader
@@ -333,7 +334,12 @@ func extractFrontMatterDelims(r *bufio.Reader, left, right []byte) (fm []byte, e
switch c {
case '"':
inQuote = !inQuote
if !escaped {
inQuote = !inQuote
}
escaped = false
case '\\':
escaped = true
case left[len(left)-1]:
if sameDelim { // YAML, TOML case
if bytes.HasSuffix(buf.Bytes(), left) && (buf.Len() == len(left) || buf.Bytes()[buf.Len()-len(left)-1] == '\n') {
@@ -396,6 +402,7 @@ func extractFrontMatterDelims(r *bufio.Reader, left, right []byte) (fm []byte, e
return buf.Bytes(), nil
}
}
}