mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-29 18:22:03 -05:00
parent
e0cf2e05bb
commit
84db6c74a0
2 changed files with 10 additions and 9 deletions
|
@ -300,12 +300,12 @@ func determineDelims(firstLine []byte) (left, right []byte) {
|
||||||
// function.
|
// function.
|
||||||
func extractFrontMatterDelims(r *bufio.Reader, left, right []byte) (fm []byte, err error) {
|
func extractFrontMatterDelims(r *bufio.Reader, left, right []byte) (fm []byte, err error) {
|
||||||
var (
|
var (
|
||||||
c byte
|
c byte
|
||||||
buf bytes.Buffer
|
buf bytes.Buffer
|
||||||
level int
|
level int
|
||||||
sameDelim = bytes.Equal(left, right)
|
sameDelim = bytes.Equal(left, right)
|
||||||
inQuote bool
|
inQuote bool
|
||||||
escaped bool
|
escapeState int
|
||||||
)
|
)
|
||||||
// Frontmatter must start with a delimiter. To check it first,
|
// Frontmatter must start with a delimiter. To check it first,
|
||||||
// pre-reads beginning delimiter length - 1 bytes from Reader
|
// pre-reads beginning delimiter length - 1 bytes from Reader
|
||||||
|
@ -334,12 +334,12 @@ func extractFrontMatterDelims(r *bufio.Reader, left, right []byte) (fm []byte, e
|
||||||
|
|
||||||
switch c {
|
switch c {
|
||||||
case '"':
|
case '"':
|
||||||
if !escaped {
|
if escapeState != 1 {
|
||||||
inQuote = !inQuote
|
inQuote = !inQuote
|
||||||
}
|
}
|
||||||
escaped = false
|
escapeState = 0
|
||||||
case '\\':
|
case '\\':
|
||||||
escaped = true
|
escapeState++
|
||||||
case left[len(left)-1]:
|
case left[len(left)-1]:
|
||||||
if sameDelim { // YAML, TOML case
|
if sameDelim { // YAML, TOML case
|
||||||
if bytes.HasSuffix(buf.Bytes(), left) && (buf.Len() == len(left) || buf.Bytes()[buf.Len()-len(left)-1] == '\n') {
|
if bytes.HasSuffix(buf.Bytes(), left) && (buf.Len() == len(left) || buf.Bytes()[buf.Len()-len(left)-1] == '\n') {
|
||||||
|
|
|
@ -304,6 +304,7 @@ func TestExtractFrontMatterDelim(t *testing.T) {
|
||||||
{`{ "title": "\"{", "other": "\"{}" }`, `{ "title": "\"{", "other": "\"{}" }`, noErrExpected},
|
{`{ "title": "\"{", "other": "\"{}" }`, `{ "title": "\"{", "other": "\"{}" }`, noErrExpected},
|
||||||
{`{ "title": "\"Foo\"" }`, `{ "title": "\"Foo\"" }`, noErrExpected},
|
{`{ "title": "\"Foo\"" }`, `{ "title": "\"Foo\"" }`, noErrExpected},
|
||||||
{`{ "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},
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, test := range tests {
|
for i, test := range tests {
|
||||||
|
|
Loading…
Reference in a new issue