Merge pull request #5263 from uber/b-element-negative
Error out on negative indices in element()
This commit is contained in:
commit
87550b2b72
|
@ -477,7 +477,7 @@ func interpolationFuncElement() ast.Function {
|
||||||
list := StringList(args[0].(string))
|
list := StringList(args[0].(string))
|
||||||
|
|
||||||
index, err := strconv.Atoi(args[1].(string))
|
index, err := strconv.Atoi(args[1].(string))
|
||||||
if err != nil {
|
if err != nil || index < 0 {
|
||||||
return "", fmt.Errorf(
|
return "", fmt.Errorf(
|
||||||
"invalid number for index, got %s", args[1])
|
"invalid number for index, got %s", args[1])
|
||||||
}
|
}
|
||||||
|
|
|
@ -778,6 +778,14 @@ func TestInterpolateFuncElement(t *testing.T) {
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// Negative number should fail
|
||||||
|
{
|
||||||
|
fmt.Sprintf(`${element("%s", "-1")}`,
|
||||||
|
NewStringList([]string{"foo"}).String()),
|
||||||
|
nil,
|
||||||
|
true,
|
||||||
|
},
|
||||||
|
|
||||||
// Too many args
|
// Too many args
|
||||||
{
|
{
|
||||||
fmt.Sprintf(`${element("%s", "0", "2")}`,
|
fmt.Sprintf(`${element("%s", "0", "2")}`,
|
||||||
|
|
Loading…
Reference in New Issue