-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix empty array index lookup #6
Conversation
Signed-off-by: Christian Haudum <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good, just a couple questions about an array with empty string, ie [""]
, thanks!
{"Empty field array", args{[]byte("{\"data\": []}"), funcError, []string{"data"}}, 10, false}, | ||
{"Empty field array with space", args{[]byte("{\"data\": [ ]}"), funcError, []string{"data"}}, 11, false}, | ||
{"Empty field array with \n", args{[]byte("{\"data\": [\n]}"), funcError, []string{"data"}}, 11, false}, | ||
{"Empty field array with newline", args{[]byte("{\"data\": [\n]}"), funcError, []string{"data"}}, 11, false}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need a test for array with an empty string, ie `[]byte("{"data": [""]}"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I understood, this is just a test to iterate over an array, not accessing an element by index in that array. The API of this library is rather confusing tbh.
path: []string{"arrString", "[1]"}, | ||
expected: "b", | ||
}, { | ||
path: []string{"arrString", "[]"}, // [] is equal to [0] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
again, do we need []string{"arrString", "[\"\"]"}
, or maybe that case works?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[]string{"keys", "[]"}
is what Loki produces when using this parser expression:
| json key[""]
[]string{"keys", "[\"\"]"}
would be equivalent to any other invalid, non-integer array index
Description: What this PR does
This PR fixes a panic that occurs when the array index is an empty string, as in