GetMany result incorrect, fixes #47

This commit is contained in:
Josh Baker 2017-09-25 04:37:57 -07:00
parent be96719f99
commit 3c91814cf6
2 changed files with 18 additions and 1 deletions

View File

@ -1790,7 +1790,6 @@ next_key:
usedPaths++
continue
}
// try to match the key to the path
// this is spaghetti code but the idea is to minimize
// 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]) != i {
goto nomatch
}
// matched and at the end of the path
goto match_atend
}

View File

@ -1071,3 +1071,18 @@ func TestValidRandom(t *testing.T) {
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)
}
}
}