diff --git a/builtins.go b/builtins.go index 9cf0f8be..77e04cf1 100644 --- a/builtins.go +++ b/builtins.go @@ -2531,6 +2531,9 @@ func builtinRemoveAt(i *interpreter, arrv value, idxv value) (value, error) { if err != nil { return nil, err } + if idx < 0 || idx >= arr.length() { + return nil, i.Error(fmt.Sprintf("Index %d out of bounds, not within [0, %v)", idx, arr.length())) + } newArr = append(newArr, arr.elements[:idx]...) newArr = append(newArr, arr.elements[idx+1:]...) diff --git a/testdata/builtinRemoveAt_neg.golden b/testdata/builtinRemoveAt_neg.golden new file mode 100644 index 00000000..bec1256e --- /dev/null +++ b/testdata/builtinRemoveAt_neg.golden @@ -0,0 +1,10 @@ +RUNTIME ERROR: Index -1 out of bounds, not within [0, 3) +------------------------------------------------- + testdata/builtinRemoveAt_neg:1:1-28 $ + +std.removeAt([1, 2, 3], -1) + +------------------------------------------------- + During evaluation + + diff --git a/testdata/builtinRemoveAt_neg.jsonnet b/testdata/builtinRemoveAt_neg.jsonnet new file mode 100644 index 00000000..93bcc85e --- /dev/null +++ b/testdata/builtinRemoveAt_neg.jsonnet @@ -0,0 +1 @@ +std.removeAt([1, 2, 3], -1) diff --git a/testdata/builtinRemoveAt_oob.golden b/testdata/builtinRemoveAt_oob.golden new file mode 100644 index 00000000..83fb6e34 --- /dev/null +++ b/testdata/builtinRemoveAt_oob.golden @@ -0,0 +1,10 @@ +RUNTIME ERROR: Index 5 out of bounds, not within [0, 3) +------------------------------------------------- + testdata/builtinRemoveAt_oob:1:1-27 $ + +std.removeAt([1, 2, 3], 5) + +------------------------------------------------- + During evaluation + + diff --git a/testdata/builtinRemoveAt_oob.jsonnet b/testdata/builtinRemoveAt_oob.jsonnet new file mode 100644 index 00000000..4ef4679f --- /dev/null +++ b/testdata/builtinRemoveAt_oob.jsonnet @@ -0,0 +1 @@ +std.removeAt([1, 2, 3], 5)