1
0
Fork 0
mirror of https://code.forgejo.org/forgejo/runner.git synced 2025-08-06 17:40:58 +00:00

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:
ChristopherHX 2022-03-22 19:05:36 +01:00 committed by GitHub
parent 75fd2e2883
commit f9514484e9
2 changed files with 7 additions and 0 deletions

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())