diff --git a/path.go b/path.go index 72554bd..b79c666 100644 --- a/path.go +++ b/path.go @@ -468,7 +468,7 @@ func (n *rootNode) String() string { func (n *rootNode) filter(node ast.Node) (ast.Node, error) { if n.child == nil { - return nil, nil + return node, nil } filtered, err := n.child.filter(node) if err != nil { diff --git a/path_test.go b/path_test.go index c0073ce..8a4d6b5 100644 --- a/path_test.go +++ b/path_test.go @@ -104,6 +104,31 @@ store: path: builder().Root().Child("store").Child(`bicycle*unicycle`).Child("price").Build(), expected: float64(20.25), }, + { + name: "$", + path: builder().Root().Build(), + expected: map[string]interface{}{ + "store": map[string]interface{}{ + "book": []interface{}{ + map[string]interface{}{ + "author": "john", + "price": uint64(10), + }, + map[string]interface{}{ + "author": "ken", + "price": uint64(12), + }, + }, + "bicycle": map[string]interface{}{ + "color": "red", + "price": 19.95, + }, + "bicycle*unicycle": map[string]interface{}{ + "price": 20.25, + }, + }, + }, + }, } t.Run("PathString", func(t *testing.T) { for _, test := range tests {