Fixed bad paths causing recursing down scalar values

This commit is contained in:
mfarah 2015-10-05 14:47:24 +11:00
parent e4d5769f29
commit 8efc46deae
2 changed files with 7 additions and 3 deletions

View File

@ -33,10 +33,10 @@ func recurse(value interface{}, head string, tail []string) interface{} {
log.Fatalf("Error accessing array: %v", err) log.Fatalf("Error accessing array: %v", err)
} }
return readArray(value.([]interface{}), index, tail) return readArray(value.([]interface{}), index, tail)
case nil: case map[interface{}]interface{}:
return nil
default:
return readMap(value.(map[interface{}]interface{}), head, tail) return readMap(value.(map[interface{}]interface{}), head, tail)
default:
return nil
} }
} }

View File

@ -44,6 +44,10 @@ func TestReadMap_key_doesnt_exist(t *testing.T) {
assertResult(t, nil, readMap(parsedData, "b.x.f", []string{"c"})) assertResult(t, nil, readMap(parsedData, "b.x.f", []string{"c"}))
} }
func TestReadMap_recurse_against_string(t *testing.T) {
assertResult(t, nil, readMap(parsedData, "a", []string{"b"}))
}
func TestReadMap_with_array(t *testing.T) { func TestReadMap_with_array(t *testing.T) {
assertResult(t, 4, readMap(parsedData, "b", []string{"d", "1"})) assertResult(t, 4, readMap(parsedData, "b", []string{"d", "1"}))
} }