From 49202930ff96ebaafca3bf00aa0feb6b2c0df6ef Mon Sep 17 00:00:00 2001 From: Darien Raymond Date: Thu, 15 Dec 2016 00:00:44 +0100 Subject: [PATCH] bug fix --- tools/conf/json/reader.go | 42 ++++++++++++++++++++++++---------- tools/conf/json/reader_test.go | 1 + 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/tools/conf/json/reader.go b/tools/conf/json/reader.go index c6b1e4df9..361091981 100644 --- a/tools/conf/json/reader.go +++ b/tools/conf/json/reader.go @@ -7,14 +7,16 @@ import ( type State byte const ( - StateContent State = 0 - StateEscape State = 1 - StateDoubleQuote State = 2 - StateSingleQuote State = 3 - StateComment State = 4 - StateSlash State = 5 - StateMultilineComment State = 6 - StateMultilineCommentStar State = 7 + StateContent State = iota + StateEscape + StateDoubleQuote + StateDoubleQuoteEscape + StateSingleQuote + StateSingleQuoteEscape + StateComment + StateSlash + StateMultilineComment + StateMultilineCommentStar ) type Reader struct { @@ -51,15 +53,31 @@ func (v *Reader) Read(b []byte) (int, error) { p = append(p, x) v.state = StateContent case StateDoubleQuote: - if x == '"' { + switch x { + case '"': v.state = StateContent + p = append(p, x) + case '\\': + v.state = StateDoubleQuoteEscape + default: + p = append(p, x) } - p = append(p, x) + case StateDoubleQuoteEscape: + p = append(p, '\\', x) + v.state = StateDoubleQuote case StateSingleQuote: - if x == '\'' { + switch x { + case '\'': v.state = StateContent + p = append(p, x) + case '\\': + v.state = StateSingleQuoteEscape + default: + p = append(p, x) } - p = append(p, x) + case StateSingleQuoteEscape: + p = append(p, '\\', x) + v.state = StateSingleQuote case StateComment: if x == '\n' { v.state = StateContent diff --git a/tools/conf/json/reader_test.go b/tools/conf/json/reader_test.go index 6cb4958b2..feede9b70 100644 --- a/tools/conf/json/reader_test.go +++ b/tools/conf/json/reader_test.go @@ -32,6 +32,7 @@ text 2*/`, ` text text 2*`}, {`"//"content`, `"//"content`}, {`abcd'//'abcd`, `abcd'//'abcd`}, + {`"\""`, `"\""`}, } for _, testCase := range data {