ohler55 / ojg

Optimized JSON for Go
MIT License
837 stars 50 forks source link

Panic on setting a nil value on JSONPath #146

Closed nervo closed 10 months ago

nervo commented 11 months ago

A panic occurs when trying to set a nil value on a JSONPath

See the following playground: https://go.dev/play/p/pyYYcThozY9

package main

import (
    "fmt"

    "github.com/ohler55/ojg/jp"
)

func main() {
    data := map[string]any{
        "foo": nil,
        "bar": 0,
        "baz": "",
    }
    fmt.Println(data)

    path, _ := jp.ParseString("foo")

    path.Set(&data, 123) // No panic, value is set
    fmt.Println(data)

    path.Set(&data, nil)  // Panic occurs :)
    fmt.Println(data)
}

By the way, i'm just testing your lib who seems to be amazing :)

ohler55 commented 11 months ago

I'll get that fixed this weekend.

ohler55 commented 10 months ago

I forgot to make the release with the fix. Actually fixed it Friday night but then forgot to checkin and release. v1.20.1 will be out in a few moments.

nervo commented 10 months ago

Aaaaand it works \o/

Good job, and thanks for the fix @ohler55 :)