forked from mirror/gjson
Fix non-existent response from multires query on empty array
This commit fixes an issue where a multires query on an empty array will result in a non-existent (empty string) result. For example `Get("[]", "#(key=value)#").Raw` resulted in an empty string. But, it should actually result in the empty array `[]`.
This commit is contained in:
parent
c75c954102
commit
d6cb589fc4
10
gjson.go
10
gjson.go
|
@ -1406,7 +1406,6 @@ func parseArray(c *parseContext, i int, path string) (int, bool) {
|
|||
}
|
||||
return false
|
||||
}
|
||||
|
||||
for i < len(c.json)+1 {
|
||||
if !rp.arrch {
|
||||
pmatch = partidx == h
|
||||
|
@ -1608,11 +1607,18 @@ func parseArray(c *parseContext, i int, path string) (int, bool) {
|
|||
c.calcd = true
|
||||
return i + 1, true
|
||||
}
|
||||
if len(multires) > 0 && !c.value.Exists() {
|
||||
if !c.value.Exists() {
|
||||
if len(multires) > 0 {
|
||||
c.value = Result{
|
||||
Raw: string(append(multires, ']')),
|
||||
Type: JSON,
|
||||
}
|
||||
} else if rp.query.all {
|
||||
c.value = Result{
|
||||
Raw: "[]",
|
||||
Type: JSON,
|
||||
}
|
||||
}
|
||||
}
|
||||
return i + 1, false
|
||||
}
|
||||
|
|
|
@ -2233,3 +2233,8 @@ func TestFlattenRemoveNonExist(t *testing.T) {
|
|||
raw := Get("[[1],[2,[[],[3]],[4,[5],[],[[[6]]]]]]", `@flatten:{"deep":true}`).Raw
|
||||
assert(t, raw == "[1,2,3,4,5,6]")
|
||||
}
|
||||
|
||||
func TestPipeEmptyArray(t *testing.T) {
|
||||
raw := Get("[]", `#(hello)#`).Raw
|
||||
assert(t, raw == "[]")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue