Error out on negative indices in element()

This commit is contained in:
Bill Fumerola 2016-02-22 14:47:17 -08:00
parent e70516a286
commit c0034e672b
2 changed files with 9 additions and 1 deletions

View File

@ -475,7 +475,7 @@ func interpolationFuncElement() ast.Function {
list := StringList(args[0].(string))
index, err := strconv.Atoi(args[1].(string))
if err != nil {
if err != nil || index < 0 {
return "", fmt.Errorf(
"invalid number for index, got %s", args[1])
}

View File

@ -778,6 +778,14 @@ func TestInterpolateFuncElement(t *testing.T) {
false,
},
// Negative number should fail
{
fmt.Sprintf(`${element("%s", "-1")}`,
NewStringList([]string{"foo"}).String()),
nil,
true,
},
// Too many args
{
fmt.Sprintf(`${element("%s", "0", "2")}`,