jlexer skipped json value validation added (#309)

* jlexer skipped json value validation added

* jlexer skipping invalid json tests added

Co-authored-by: michael <michael@tutti.ch>
This commit is contained in:
komika
2020-10-07 20:59:05 +03:00
committed by GitHub
co-authored by michael
parent 45d2d57d45
commit fca00f44f1
2 changed files with 13 additions and 0 deletions
+9
View File
@@ -529,6 +529,7 @@ func (r *Lexer) Skip() {
func (r *Lexer) SkipRecursive() {
r.scanToken()
var start, end byte
startPos := r.start
switch r.token.delimValue {
case '{':
@@ -554,6 +555,14 @@ func (r *Lexer) SkipRecursive() {
level--
if level == 0 {
r.pos += i + 1
if !json.Valid(r.Data[startPos:r.pos]) {
r.pos = len(r.Data)
r.fatalError = &LexerError{
Reason: "skipped array/object json value is invalid",
Offset: r.pos,
Data: string(r.Data[r.pos:]),
}
}
return
}
case c == '\\' && inQuotes:
+4
View File
@@ -201,6 +201,10 @@ func TestSkipRecursive(t *testing.T) {
// object with double slashes at the end of string
{toParse: `{"a":"hey\\"}, 4`, left: ", 4"},
// make sure skipping an invalid json results in an error
{toParse: `{"a": [ ##invalid json## ]}, 4`, wantError: true},
{toParse: `{"a": [ [1], [ ##invalid json## ]]}, 4`, wantError: true},
} {
l := Lexer{Data: []byte(test.toParse)}