jsonparser icon indicating copy to clipboard operation
jsonparser copied to clipboard

Leading whitespaces lead to incorrect results (jsonparser.ArrayEach)

Open coxx opened this issue 6 years ago • 5 comments

data := []byte(`[1, 2, 3]`)
jsonparser.ArrayEach(data, func(value []byte, dataType jsonparser.ValueType, offset int, err error) {
    fmt.Println(string(value))
})

returns

1 2 3

but

data := []byte(`    [1, 2, 3]`)
jsonparser.ArrayEach(data, func(value []byte, dataType jsonparser.ValueType, offset int, err error) {
    fmt.Println(string(value))
})

returns

[1, 2, 3]

coxx avatar Oct 24 '18 22:10 coxx

Similarly, Delete seems to "silently" fail when there is leading whitespace: This works: https://play.golang.org/p/Jub6y91ObT0 This doesn't: https://play.golang.org/p/FLM_k3GU6nc

sauerbraten avatar Jan 22 '21 08:01 sauerbraten

Should be a pretty simple fix, e.g. just skip spaces at the start. PRs are welcomed :)

buger avatar Jan 22 '21 17:01 buger

Fixed now, thanks @daria-kay!

buger avatar Mar 19 '21 18:03 buger

Have to re-open because of bug found by OSS-Fuzz. See attached PR for error details.

buger avatar Mar 21 '21 09:03 buger

OSS-Fuzz bug is solved by #227. Can issue be closed?

kadukm avatar May 11 '21 08:05 kadukm