mirror of
https://github.com/mikefarah/yq.git
synced 2024-11-13 22:38:04 +00:00
Handle index out of range when reading arrays
This commit is contained in:
parent
c4af37ed68
commit
d1c545cca0
@ -36,6 +36,10 @@ func recurse(value interface{}, head string, tail []string) interface{} {
|
||||
}
|
||||
|
||||
func readArray(array []interface{}, head int64, tail []string) interface{} {
|
||||
if head > int64(len(array)) {
|
||||
return nil
|
||||
}
|
||||
|
||||
value := array[head]
|
||||
if len(tail) > 0 {
|
||||
return recurse(value, tail[0], tail[1:len(tail)])
|
||||
|
@ -35,6 +35,10 @@ func TestReadMap_array(t *testing.T) {
|
||||
assertResult(t, 4, readMap(parsedData, "b", []string{"d", "1"}))
|
||||
}
|
||||
|
||||
func TestReadMap_array_out_of_bounds(t *testing.T) {
|
||||
assertResult(t, nil, readMap(parsedData, "b", []string{"d", "3"}))
|
||||
}
|
||||
|
||||
func TestWrite_simple(t *testing.T) {
|
||||
|
||||
write(parsedData, "b", []string{"c"}, "4")
|
||||
|
Loading…
Reference in New Issue
Block a user