Skip to content

Commit

Permalink
more coverage for skipping errors
Browse files Browse the repository at this point in the history
  • Loading branch information
yosiat committed Oct 5, 2022
1 parent f6b7e9c commit 7695271
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
6 changes: 1 addition & 5 deletions flatten_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,11 +313,7 @@ func (fj *flattenJSON) readArray(pathName []byte) error {

switch ch {
case '"':
if fj.skipping > 0 {
err = fj.skipStringValue()
} else {
val, err = fj.readStringValue()
}
val, err = fj.readStringValue()
isLeaf = true
case 't':
val, err = fj.readLiteral(trueBytes)
Expand Down
25 changes: 25 additions & 0 deletions flatten_json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,31 @@ func TestFJStrings(t *testing.T) {
)
}

func TestFJSkippingErrors(t *testing.T) {
events := []string{
// Block with strings that never ends.
`{ "a": { "v": "hello`,
`{ "a": ["hello`,
// String that never ends.
`{ "k": "`,
// Truncated block
`{ "k": { "a":`,
`{ "k": {`,
`{ "k": [1, `,
`{ "k": [`,
}

matcher := fakeMatcher("non_existing_value")
f := newJSONFlattener()

for _, event := range events {
fields, err := f.Flatten([]byte(event), matcher)
if err == nil {
t.Errorf("Expected to fail [%s], but got %d fields", string(event), len(fields))
}
}
}

func TestFJSkippingBlocks(t *testing.T) {
j := `{
"skipped_objects_with_objects": {
Expand Down

0 comments on commit 7695271

Please sign in to comment.