Fixing EOF error to appear while having double slashes at the end of the string

This commit is contained in:
Anton Velikanov
2016-09-01 17:02:09 +03:00
parent 34560e358d
commit 6f997d527e
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)}