Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down
19 changes: 12 additions & 7 deletions parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}

Expand Down