Skip to content

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

Description

@pavanmachavolu

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions