Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Commit c0034e6

Browse files
committed
Error out on negative indices in element()
1 parent e70516a commit c0034e6

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

config/interpolate_funcs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ func interpolationFuncElement() ast.Function {
475475
list := StringList(args[0].(string))
476476

477477
index, err := strconv.Atoi(args[1].(string))
478-
if err != nil {
478+
if err != nil || index < 0 {
479479
return "", fmt.Errorf(
480480
"invalid number for index, got %s", args[1])
481481
}

config/interpolate_funcs_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,14 @@ func TestInterpolateFuncElement(t *testing.T) {
778778
false,
779779
},
780780

781+
// Negative number should fail
782+
{
783+
fmt.Sprintf(`${element("%s", "-1")}`,
784+
NewStringList([]string{"foo"}).String()),
785+
nil,
786+
true,
787+
},
788+
781789
// Too many args
782790
{
783791
fmt.Sprintf(`${element("%s", "0", "2")}`,

0 commit comments

Comments
 (0)