Skip to content

Commit

Permalink
fix: wrongly check each nodes' type (#525)
Browse files Browse the repository at this point in the history
  • Loading branch information
AsterDY committed Sep 11, 2023
1 parent ada8e06 commit a1555f1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
6 changes: 3 additions & 3 deletions ast/encode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,15 +169,15 @@ func (j *SortableNode) MarshalJSON() ([]byte, error) {
}

func TestMarshalSort(t *testing.T) {
var data = `{"d":3,"a":{"c":1,"b":2}}`
var data = `{"d":3,"a":{"c":1,"b":2},"e":null}`
var obj map[string]*SortableNode
require.NoError(t, json.Unmarshal([]byte(data), &obj))
out, err := json.Marshal(obj)
require.NoError(t, err)
require.Equal(t, `{"a":{"b":2,"c":1},"d":3}`, string(out))
require.Equal(t, `{"a":{"b":2,"c":1},"d":3,"e":null}`, string(out))
out, err = json.Marshal(obj)
require.NoError(t, err)
require.Equal(t, `{"a":{"b":2,"c":1},"d":3}`, string(out))
require.Equal(t, `{"a":{"b":2,"c":1},"d":3,"e":null}`, string(out))
}

func BenchmarkEncodeRaw_Sonic(b *testing.B) {
Expand Down
3 changes: 2 additions & 1 deletion ast/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,7 @@ func (self *Node) MapUseNode() (map[string]Node, error) {
// return self.toGenericObjectUsePair()
// }

//go:nocheckptr
func (self *Node) unsafeMap() (*linkedPairs, error) {
if err := self.skipAllKey(); err != nil {
return nil, err
Expand All @@ -866,7 +867,7 @@ func (self *Node) SortKeys(recurse bool) error {
} else {
var err error
err2 := self.ForEach(func(path Sequence, node *Node) bool {
it := self.itype()
it := node.itype()
if it == types.V_ARRAY || it == types.V_OBJECT {
err = node.SortKeys(recurse)
if err != nil {
Expand Down

0 comments on commit a1555f1

Please sign in to comment.