From 29205ba586381dcf7e68f8bca655a54ca8b94ade Mon Sep 17 00:00:00 2001 From: sawka Date: Sun, 26 Mar 2023 23:31:22 -0700 Subject: [PATCH] for non-relative resolves, return nil if the number is out of range --- pkg/cmdrunner/resolver.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pkg/cmdrunner/resolver.go b/pkg/cmdrunner/resolver.go index 1b5aaa6cc..cce62160b 100644 --- a/pkg/cmdrunner/resolver.go +++ b/pkg/cmdrunner/resolver.go @@ -162,6 +162,8 @@ func resolveByPosition(isNumeric bool, allItems []ResolveItem, curId string, pos } } finalPos = curIdx + posArg.Pos + finalPos = boundInt(finalPos, len(items), posArg.IsWrap) + return &items[finalPos-1] } else if isNumeric { // these resolve items have a "Num" set that should be used to look up non-relative positions // use allItems for numeric resolve @@ -174,9 +176,11 @@ func resolveByPosition(isNumeric bool, allItems []ResolveItem, curId string, pos } else { // non-numeric means position is just the index finalPos = posArg.Pos + if finalPos <= 0 || finalPos > len(items) { + return nil + } + return &items[finalPos-1] } - finalPos = boundInt(finalPos, len(items), posArg.IsWrap) - return &items[finalPos-1] } func resolveRemoteArg(remoteArg string) (*sstore.RemotePtrType, error) {