mirror of https://github.com/tidwall/gjson.git
GetMany result incorrect, fixes #47
This commit is contained in:
parent
be96719f99
commit
3c91814cf6
4
gjson.go
4
gjson.go
|
@ -1790,7 +1790,6 @@ next_key:
|
||||||
usedPaths++
|
usedPaths++
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// try to match the key to the path
|
// try to match the key to the path
|
||||||
// this is spaghetti code but the idea is to minimize
|
// this is spaghetti code but the idea is to minimize
|
||||||
// calls and variable assignments when comparing the
|
// calls and variable assignments when comparing the
|
||||||
|
@ -1810,6 +1809,9 @@ next_key:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(paths[j]) <= len(key) || kplen != 0 {
|
if len(paths[j]) <= len(key) || kplen != 0 {
|
||||||
|
if len(paths[j]) != i {
|
||||||
|
goto nomatch
|
||||||
|
}
|
||||||
// matched and at the end of the path
|
// matched and at the end of the path
|
||||||
goto match_atend
|
goto match_atend
|
||||||
}
|
}
|
||||||
|
|
|
@ -1071,3 +1071,18 @@ func TestValidRandom(t *testing.T) {
|
||||||
validpayload(b[:n], 0)
|
validpayload(b[:n], 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGetMany47(t *testing.T) {
|
||||||
|
json := `{"bar": {"id": 99, "mybar": "my mybar" }, "foo": {"myfoo": [605]}}`
|
||||||
|
paths := []string{"foo.myfoo", "bar.id", "bar.mybar", "bar.mybarx"}
|
||||||
|
expected := []string{"[605]", "99", "my mybar", ""}
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue