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

panic: runtime error: index out of range #127

Closed
krpn opened this issue Oct 31, 2017 · 6 comments
Closed

panic: runtime error: index out of range #127

krpn opened this issue Oct 31, 2017 · 6 comments

Comments

@krpn
Copy link

krpn commented Oct 31, 2017

This code panics with index out of range error:

package main

import (
	"fmt"
	"github.com/buger/jsonparser"
)

func main() {
	data := []byte(`{"some":0}some":[{"some":[{"some":"some"}]}]}some"}]}],"some":"some"}`)

	val, _, _, err := jsonparser.Get(data, "x")
	if err != nil {
		fmt.Println(err)
	} else {
		fmt.Println(val)
	}
}

Error:

panic: runtime error: index out of range

goroutine 1 [running]:
github.com/buger/jsonparser.searchKeys(0xc042010190, 0x45, 0x50, 0xc04202df50, 0x1, 0x1, 0x0)
	.../src/github.com/buger/jsonparser/parser.go:259 +0x94a
github.com/buger/jsonparser.internalGet(0xc042010190, 0x45, 0x50, 0xc04202df50, 0x1, 0x1, 0x43cc6a, 0xc042010190, 0x4c9289, 0x45, ...)
	.../src/github.com/buger/jsonparser/parser.go:822 +0x290
github.com/buger/jsonparser.Get(0xc042010190, 0x45, 0x50, 0xc04202df50, 0x1, 0x1, 0x404393, 0xc0420120b8, 0x0, 0x20, ...)
	.../src/github.com/buger/jsonparser/parser.go:816 +0x7a
main.main()
	.../src/tests/main.go:11 +0xb7
@buger
Copy link
Owner

buger commented Oct 31, 2017

I assume it should give error instead of panic, because of invalid JSON here: 0}some

@krpn
Copy link
Author

krpn commented Oct 31, 2017

Yes, error instead of panic is needed.

@afiune
Copy link

afiune commented Aug 7, 2018

@buger I'm going through the same problem, wondering if you are actively improving this repository? Would you like to have some help with this issue? Cheers!

@buger
Copy link
Owner

buger commented Aug 8, 2018

@afiune help is always encouraged :)

@buger
Copy link
Owner

buger commented Aug 8, 2018

Just merged #137, try now

@krpn
Copy link
Author

krpn commented Aug 8, 2018

It works, thank you.

@krpn krpn closed this as completed Aug 8, 2018
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

3 participants