Merge pull request #56 from velanse/master

SkipRecursive fails while having double slashes at the end of the string
This commit is contained in:
Victor Starodub
2016-09-01 18:26:57 +04:00
committed by GitHub
2 changed files with 9 additions and 3 deletions
+6 -3
View File
@@ -506,7 +506,7 @@ func (r *Lexer) SkipRecursive() {
return
}
case c == '\\' && inQuotes:
wasEscape = true
wasEscape = !wasEscape
continue
case c == '"' && inQuotes:
inQuotes = wasEscape
@@ -516,8 +516,11 @@ func (r *Lexer) SkipRecursive() {
wasEscape = false
}
r.pos = len(r.Data)
r.err = io.EOF
}
r.err = &LexerError{
Reason: "EOF reached while skipping array/object or token",
Offset: r.pos,
Data: string(r.Data[r.pos:]),
}}
// Raw fetches the next item recursively as a data slice
func (r *Lexer) Raw() []byte {
+3
View File
@@ -157,6 +157,9 @@ func TestSkipRecursive(t *testing.T) {
{toParse: `{"a\"}":1}, 4`, left: ", 4"},
{toParse: `{"a{":1}, 4`, left: ", 4"},
{toParse: `{"a\"{":1}, 4`, left: ", 4"},
// object with double slashes at the end of string
{toParse: `{"a":"hey\\"}, 4`, left: ", 4"},
} {
l := Lexer{Data: []byte(test.toParse)}