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

EachKey panics on invalid JSON payload #121

Closed
xxuejie opened this issue Sep 21, 2017 · 1 comment
Closed

EachKey panics on invalid JSON payload #121

xxuejie opened this issue Sep 21, 2017 · 1 comment

Comments

@xxuejie
Copy link

xxuejie commented Sep 21, 2017

Following code would first result in an err, then would panic:

package main

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

func main() {
	data := `{"id":`

	jsonparser.EachKey([]byte(data), func(idx int, value []byte, vt jsonparser.ValueType, currentErr error) {
		if currentErr != nil {
			fmt.Printf("Error: %v\n", currentErr)
			return
		}
		fmt.Printf("idx: %d value: %s\n", idx, string(value))
	}, []string{"id"}, []string{"method"}, []string{"params"})
}

Maybe this is similar to #100?

@gladkikhartem
Copy link

gladkikhartem commented Sep 28, 2017

I've found error output not being checked from Get method here https://github.com/buger/jsonparser/blob/master/parser.go#L410
adding simple
if e != nil {
return -1
} helped me

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