Merge pull request #2 from chaos95/master

Handle 'index out of range' errors more gracefully
This commit is contained in:
Mike Farah 2016-03-19 13:05:57 +11:00
commit 037314af8a
2 changed files with 12 additions and 1 deletions

View File

@ -58,7 +58,7 @@ func recurse(value interface{}, head string, tail []string) interface{} {
}
func readArray(array []interface{}, head int64, tail []string) interface{} {
if head > int64(len(array)) {
if head >= int64(len(array)) {
return nil
}

View File

@ -83,6 +83,17 @@ b:
assertResult(t, nil, readMap(data, "b", []string{"d", "3"}))
}
func TestReadMap_with_array_out_of_bounds_by_1(t *testing.T) {
var data = parseData(`
---
b:
d:
- 3
- 4
`)
assertResult(t, nil, readMap(data, "b", []string{"d", "2"}))
}
func TestReadMap_with_array_splat(t *testing.T) {
var data = parseData(`
e: