mdaverde / jsonpath

jsonpath golang library to help with getting and setting values on paths (even nonexistent paths)
https://pkg.go.dev/github.com/mdaverde/jsonpath
MIT License
22 stars 5 forks source link

unexpected json path cause panic #5

Open LuShan123888 opened 5 months ago

LuShan123888 commented 5 months ago

Hello, Thanks much for the awesome API. It is helping me a lot.

When I call the jsonpath.get function with the following parameters, the program appears panic instead of returning the error through err.

func main() {
    data := make(map[string]any)
    _, err := jsonpath.Get(&data, `[["a","a"],["b","b"],["c","c.c"],["d.d","d.d"]`)
    if err != nil {
        print(err)
    }
}

Result:

panic: runtime error: slice bounds out of range [5:2]

goroutine 1 [running]:
github.com/mdaverde/jsonpath.tokenizePath({0x10104ada3, 0x31})
        /Users/bytedance/go/pkg/mod/github.com/mdaverde/jsonpath@v0.2.1/jsonpath.go:34 +0x35c
github.com/mdaverde/jsonpath.Get({0x10106d060, 0x1400000e028}, {0x10104ada3?, 0x0?})
        /Users/bytedance/go/pkg/mod/github.com/mdaverde/jsonpath@v0.2.1/jsonpath.go:100 +0x30
main.main()
        /Users/bytedance/go/src/code.byted.org/lushan/Go/main.go:9 +0x70

Process finished with the exit code 2

Please consider this on urgent basis.