bytedance / sonic

A blazingly fast JSON serializing & deserializing library
Apache License 2.0
6.59k stars 327 forks source link

fix:(ast) SortKeys(true) panic when not loaded-all #603

Closed AsterDY closed 4 months ago

AsterDY commented 4 months ago

Reproduce Code

func TestNodeSortKeys2(t *testing.T) {
    root, err := NewSearcher(_TwitterJson).GetByPath()
    if err != nil {
        t.Fatal(err)
    }
    t.Run("single", func(t *testing.T) {
        r := root.Get("statuses")
        if r.Check() != nil {
            t.Fatal(r.Error())
        }
        require.NoError(t, root.SortKeys(false))
    })
    t.Run("recurse", func(t *testing.T) {
        require.NoError(t, root.SortKeys(true))
    })
}
--  runtime error: invalid memory address or nil pointer dereference 

Reason

sortKey() use unsafeMap() at the beginning , which doesn't considerV_RAW type nodes