diff --git a/parser.go b/parser.go index 26d1cd8..1b6c8bb 100644 --- a/parser.go +++ b/parser.go @@ -445,11 +445,10 @@ func EachKey(data []byte, cb func(int, []byte, ValueType, error), paths ...[]str match = pi - i++ pathsMatched++ pathFlags |= bitwiseFlags[pi+1] - v, dt, _, e := Get(data[i:]) + v, dt, _, e := Get(data[i+1:]) cb(pi, v, dt, e) if pathsMatched == len(paths) { @@ -930,7 +929,7 @@ func ArrayEach(data []byte, cb func(value []byte, dataType ValueType, offset int return -1, MalformedJsonError } - offset = nT+1 + offset = nT + 1 if len(keys) > 0 { if offset = searchKeys(data, keys...); offset == -1 { diff --git a/parser_test.go b/parser_test.go index b67a342..b02ccb6 100644 --- a/parser_test.go +++ b/parser_test.go @@ -1420,9 +1420,9 @@ func TestArrayEachWithWhiteSpace(t *testing.T) { keys []string } tests := []struct { - name string - args args - wantErr bool + name string + args args + wantErr bool }{ {"Array with white space", args{[]byte(` ["AAA", "BBB", "CCC"]`), funcSuccess, []string{}}, false}, {"Array with only one character after white space", args{[]byte(` 1`), funcError, []string{}}, true}, @@ -1675,8 +1675,9 @@ func TestEachKey(t *testing.T) { {"arrInt", "[3]"}, {"arrInt", "[5]"}, // Should not find last key {"nested"}, - {"arr", "["}, // issue#177 Invalid arguments - {"a\n", "b\n"}, // issue#165 + {"arr", "["}, // issue#177 Invalid arguments + {"a\n", "b\n"}, // issue#165 + {"nested", "b"}, // Should find repeated key } keysFound := 0 @@ -1729,13 +1730,17 @@ func TestEachKey(t *testing.T) { if string(value) != "99" { t.Error("Should find 10 key", string(value)) } + case 12: + if string(value) != "2" { + t.Errorf("Should find 11 key") + } default: t.Errorf("Should find only 10 keys, got %v key", idx) } }, paths...) - if keysFound != 10 { - t.Errorf("Should find 10 keys: %d", keysFound) + if keysFound != 11 { + t.Errorf("Should find 11 keys: %d", keysFound) } }