Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get call panics on empty json array or invalid json with an empty path - expecting an error to be returned #247

Open
pavanmachavolu opened this issue Jun 19, 2022 · 0 comments

Comments

@pavanmachavolu
Copy link

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant