diff --git a/pkg/exprparser/interpreter.go b/pkg/exprparser/interpreter.go index 81eec07..787bbda 100644 --- a/pkg/exprparser/interpreter.go +++ b/pkg/exprparser/interpreter.go @@ -170,6 +170,9 @@ func (impl *interperterImpl) evaluateIndexAccess(indexAccessNode *actionlint.Ind case reflect.Int: switch leftValue.Kind() { case reflect.Slice: + if rightValue.Int() < 0 || rightValue.Int() >= int64(leftValue.Len()) { + return nil, nil + } return leftValue.Index(int(rightValue.Int())).Interface(), nil default: return nil, fmt.Errorf("Unable to index on non-slice value: %s", leftValue.Kind()) diff --git a/pkg/exprparser/interpreter_test.go b/pkg/exprparser/interpreter_test.go index 32a94e4..83078d6 100644 --- a/pkg/exprparser/interpreter_test.go +++ b/pkg/exprparser/interpreter_test.go @@ -50,6 +50,10 @@ func TestOperators(t *testing.T) { {"github.action[0]", nil, "string-index", "Unable to index on non-slice value: string"}, {"fromJSON('[0,1]')[1]", 1.0, "array-index", ""}, {"(github.event.commits.*.author.username)[0]", "someone", "array-index-0", ""}, + {"fromJSON('[0,1]')[2]", nil, "array-index-out-of-bounds-0", ""}, + {"fromJSON('[0,1]')[34553]", nil, "array-index-out-of-bounds-1", ""}, + {"fromJSON('[0,1]')[-1]", nil, "array-index-out-of-bounds-2", ""}, + {"fromJSON('[0,1]')[-34553]", nil, "array-index-out-of-bounds-3", ""}, {"!true", false, "not", ""}, {"1 < 2", true, "less-than", ""}, {`'b' <= 'a'`, false, "less-than-or-equal", ""},