Skip to content

Commit 037314a

Browse files
committed
Merge pull request #2 from chaos95/master
Handle 'index out of range' errors more gracefully
2 parents 7ef556f + 2a283b4 commit 037314a

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

data_navigator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func recurse(value interface{}, head string, tail []string) interface{} {
5858
}
5959

6060
func readArray(array []interface{}, head int64, tail []string) interface{} {
61-
if head > int64(len(array)) {
61+
if head >= int64(len(array)) {
6262
return nil
6363
}
6464

data_navigator_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,17 @@ b:
8383
assertResult(t, nil, readMap(data, "b", []string{"d", "3"}))
8484
}
8585

86+
func TestReadMap_with_array_out_of_bounds_by_1(t *testing.T) {
87+
var data = parseData(`
88+
---
89+
b:
90+
d:
91+
- 3
92+
- 4
93+
`)
94+
assertResult(t, nil, readMap(data, "b", []string{"d", "2"}))
95+
}
96+
8697
func TestReadMap_with_array_splat(t *testing.T) {
8798
var data = parseData(`
8899
e:

0 commit comments

Comments
 (0)