Added support for dereferenced map properties (#2635)

* Added support for dereferenced properties

* Added negative test

* Update pkg/exprparser/functions_test.go

Co-authored-by: ChristopherHX <christopher.homberger@web.de>

* Update pkg/exprparser/functions_test.go

Co-authored-by: ChristopherHX <christopher.homberger@web.de>

* fix lint

---------

Co-authored-by: m1r4c <lars-github@domesjo.com>
Co-authored-by: ChristopherHX <christopher.homberger@web.de>
This commit is contained in:
m1r4c
2025-01-31 20:14:24 +01:00
committed by GitHub
parent 7c45ad68cb
commit 9dd0854a67
3 changed files with 67 additions and 0 deletions

View File

@@ -229,6 +229,10 @@ func (impl *interperterImpl) evaluateObjectDeref(objectDerefNode *actionlint.Obj
return nil, err
}
_, receiverIsDeref := objectDerefNode.Receiver.(*actionlint.ArrayDerefNode)
if receiverIsDeref {
return impl.getPropertyValueDereferenced(reflect.ValueOf(left), objectDerefNode.Property)
}
return impl.getPropertyValue(reflect.ValueOf(left), objectDerefNode.Property)
}
@@ -312,6 +316,34 @@ func (impl *interperterImpl) getPropertyValue(left reflect.Value, property strin
return nil, nil
}
func (impl *interperterImpl) getPropertyValueDereferenced(left reflect.Value, property string) (value interface{}, err error) {
switch left.Kind() {
case reflect.Ptr:
return impl.getPropertyValue(left, property)
case reflect.Struct:
return impl.getPropertyValue(left, property)
case reflect.Map:
iter := left.MapRange()
var values []interface{}
for iter.Next() {
value, err := impl.getPropertyValue(iter.Value(), property)
if err != nil {
return nil, err
}
values = append(values, value)
}
return values, nil
case reflect.Slice:
return impl.getPropertyValue(left, property)
}
return nil, nil
}
func (impl *interperterImpl) getMapValue(value reflect.Value) (interface{}, error) {
if value.Kind() == reflect.Ptr {
return impl.getMapValue(value.Elem())