Skip to content

Commit baa0fb6

Browse files
committed
fix: range panic
1 parent 5aff922 commit baa0fb6

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

s3secrets-helper/s3/s3.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,13 @@ func (c *Client) ListSuffix(prefix string, suffixes []string) ([]string, error)
143143
for i, object := range resp.Contents {
144144
for _, suffix := range suffixes {
145145
if strings.HasSuffix(*object.Key, suffix) {
146-
keys = append(keys, *object.Key)
147-
resp.Contents = append(resp.Contents[:i], resp.Contents[i+1:]...) //since we have a match, pop it
148-
break //... then break out of the suffix loop
146+
if i < len(resp.Contents)-1 {
147+
keys = append(keys, *object.Key)
148+
resp.Contents = append(resp.Contents[:i], resp.Contents[i+1:]...) //since we have a match, pop it
149+
break //... then break out of the suffix loop
150+
} else {
151+
keys = append(keys, *object.Key) // No need to pop the object as we are at the end of the list
152+
} //... then break out of the suffix loop
149153
}
150154
}
151155
}

0 commit comments

Comments
 (0)