Fix: panic: reflect: slice index out of range (#1066)

* Fix: panic: reflect: slice index out of range

* Update interpreter.go

* [no ci] Return null for negative indexes

* Add tests for index access

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
ChristopherHXandmergify[bot] authored and GitHub committed 2022-03-22 14:05:36 -04:00
1 parent 380bd581b1
commit a970145c95
2 files changed
+7

No files matched your search

+3
View File
@@ -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())