Get call panics on empty json array or invalid json with an empty path - expecting an error to be returned
pavanmachavolu opened this issue · 0 comments
pavanmachavolu commented
Versions:
Go 1.18.1
jsonparser v1.1.1
jsonparser.Get
panics on array input with empty string in path. Details below
Try these
jsonparser.Get([]byte(`{}`), "")
jsonparser.Get([]byte(`{`), "")
These return proper errors
non-existent -1 Key path not found
Now try the below ones
jsonparser.Get([]byte(`[]`), "")
jsonparser.Get([]byte(`[`), "")
Both of them panic with below error. Expecting these calls also return error like above.
panic: runtime error: index out of range [0] with length 0 [recovered]
panic: runtime error: index out of range [0] with length 0
goroutine 119 [running]:
testing.tRunner.func1.2({0x105ba35e0, 0x140004bc5b8})
/opt/homebrew/Cellar/go/1.18.1/libexec/src/testing/testing.go:1389 +0x1c8
testing.tRunner.func1()
/opt/homebrew/Cellar/go/1.18.1/libexec/src/testing/testing.go:1392 +0x384
panic({0x105ba35e0, 0x140004bc5b8})
/opt/homebrew/Cellar/go/1.18.1/libexec/src/runtime/panic.go:838 +0x204