Skip to content

Commit e05546d

Browse files
author
Ubuntu
committed
Bugfix: Get() via index fails on string
1 parent 016ea00 commit e05546d

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

parser.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,14 @@ func searchKeys(data []byte, keys ...string) int {
183183
var curIdx int
184184
var valueFound []byte
185185
var valueOffset int
186-
187186
ArrayEach(data[i:], func(value []byte, dataType ValueType, offset int, err error) {
188187
if curIdx == aIdx {
189188
valueFound = value
190189
valueOffset = offset
190+
if dataType == String {
191+
valueOffset = valueOffset - 2
192+
valueFound = data[i + valueOffset:i + valueOffset + len(value) + 2]
193+
}
191194
}
192195
curIdx += 1
193196
})

parser_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,13 @@ var getTests = []GetTest{
399399
isFound: true,
400400
data: `{"b":"2"}`,
401401
},
402+
{
403+
desc: "get string from array",
404+
json: `{"a":[{"b":1},"foo", 3],"c":{"c":[1,2]}}`,
405+
path: []string{"a", "[1]"},
406+
isFound: true,
407+
data: "foo",
408+
},
402409
{
403410
desc: "key in path is index",
404411
json: `{"a":[{"b":"1"},{"b":"2"},3],"c":{"c":[1,2]}}`,

0 commit comments

Comments
 (0)