mirror of
https://github.com/netbirdio/easyjson.git
synced 2026-05-22 18:44:42 -07:00
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:
@@ -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:
|
||||
|
||||
@@ -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)}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user