From 6f997d527e962964fe20d3e8518df5decc7cf45b Mon Sep 17 00:00:00 2001 From: Anton Velikanov Date: Thu, 1 Sep 2016 17:02:09 +0300 Subject: [PATCH] Fixing EOF error to appear while having double slashes at the end of the string --- jlexer/lexer.go | 9 ++++++--- jlexer/lexer_test.go | 3 +++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/jlexer/lexer.go b/jlexer/lexer.go index 36cd820..c3d4ed2 100644 --- a/jlexer/lexer.go +++ b/jlexer/lexer.go @@ -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 { diff --git a/jlexer/lexer_test.go b/jlexer/lexer_test.go index b8e70f0..58f5fe9 100644 --- a/jlexer/lexer_test.go +++ b/jlexer/lexer_test.go @@ -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)}