From 06ddb9467b36e21e9800da5ee236ba564024212c Mon Sep 17 00:00:00 2001 From: Mateusz Hawrus Date: Tue, 25 Jun 2024 22:43:09 +0200 Subject: [PATCH] correct root path handling --- path.go | 2 +- path_test.go | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/path.go b/path.go index 72554bd8..b79c6669 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 c0073cec..8a4d6b50 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 {