GetMany result value missing, fixes #48

This commit is contained in:
Josh Baker 2017-09-25 04:39:06 -07:00
parent 3c91814cf6
commit 5a69e67cfd
2 changed files with 18 additions and 0 deletions

View File

@ -1850,6 +1850,9 @@ next_key:
nomatch: // noop label
}
if !hasMatch && i < len(json) && json[i] == '}' {
return i + 1, true
}
if !parsedVal {
if hasMatch {
// we found a match and the value has not been parsed yet.

View File

@ -1086,3 +1086,18 @@ func TestGetMany47(t *testing.T) {
}
}
}
func TestGetMany48(t *testing.T) {
json := `{"bar": {"id": 99, "xyz": "my xyz"}, "foo": {"myfoo": [605]}}`
paths := []string{"foo.myfoo", "bar.id", "bar.xyz", "bar.abc"}
expected := []string{"[605]", "99", "my xyz", ""}
results := GetMany(json, paths...)
if len(expected) != len(results) {
t.Fatalf("expected %v, got %v", len(expected), len(results))
}
for i, path := range paths {
if results[i].String() != expected[i] {
t.Fatalf("expected '%v', got '%v' for path '%v'", expected[i], results[i].String(), path)
}
}
}