Skip to content

Commit

Permalink
fix: set Array unexpectedly (#569)
Browse files Browse the repository at this point in the history
  • Loading branch information
AsterDY authored Dec 28, 2023
1 parent 29dfcca commit ec2ab23
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion ast/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -534,10 +534,12 @@ func (self *Node) Set(key string, node Node) (bool, error) {
if err := node.Check(); err != nil {
return false, err
}

if self.t == _V_NONE || self.t == types.V_NULL {
*self = NewObject([]Pair{{key, node}})
return false, nil
} else if self.itype() != types.V_OBJECT {
return false, ErrUnsupportType
}

p := self.Get(key)
Expand Down
5 changes: 5 additions & 0 deletions ast/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1204,6 +1204,11 @@ func TestNodeGetByPath(t *testing.T) {
}

func TestNodeSet(t *testing.T) {
arr := NewRaw(`[]`)
ex, ee := arr.Set("a", NewNumber("-1"))
if ex || ee == nil {
t.Fatal()
}
empty := Node{}
err := empty.Add(Node{})
if err != nil {
Expand Down

0 comments on commit ec2ab23

Please sign in to comment.