parser: Final (!) fix for issue with escaped JSON front matter
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Sat, 8 Jul 2017 16:43:36 +0000 (18:43 +0200)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Sat, 8 Jul 2017 16:43:36 +0000 (18:43 +0200)
Fixes #3682

parser/page.go
parser/parse_frontmatter_test.go

index f17ba1767f8cb3c887eb68020db5ceb2dcdefd44..1537915f4926080366052be2f49cdd5fce3f582a 100644 (file)
@@ -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
+               }
+
        }
 }
 
index b7764ca2d064e82fe5c60c2e5edc47db629d2ade..14e69abfdcc223346b8c58cae5885cd4988e94ce 100644 (file)
@@ -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 {