Skip to content

Commit

Permalink
selector: support negative index on lists
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelMure committed Sep 1, 2024
1 parent 53af455 commit bd7ff3d
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion capability/policy/selector/selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,11 @@ func resolve(sel Selector, subject ipld.Node, at []string) (ipld.Node, []ipld.No
} else {
at = append(at, fmt.Sprintf("%d", seg.Index()))
if cur != nil && cur.Kind() == datamodel.Kind_List {
n, err := cur.LookupByIndex(int64(seg.Index()))
idx := int64(seg.Index())
if idx < 0 {
idx = cur.Length() + idx
}
n, err := cur.LookupByIndex(idx)
if err != nil {
if isMissing(err) {
if seg.Optional() {
Expand Down

0 comments on commit bd7ff3d

Please sign in to comment.