From bd7ff3dc3fa50cf5bf64efdbfc8e1958a2a4a07e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Mur=C3=A9?= Date: Sun, 1 Sep 2024 17:08:49 +0200 Subject: [PATCH] selector: support negative index on lists --- capability/policy/selector/selector.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/capability/policy/selector/selector.go b/capability/policy/selector/selector.go index ec4c144..53b1965 100644 --- a/capability/policy/selector/selector.go +++ b/capability/policy/selector/selector.go @@ -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() {