Skip to content

Commit 1089aa9

Browse files
committed
fixes #807: make in operator return false for unexported struct fields
1 parent eecf371 commit 1089aa9

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

vm/runtime/runtime.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,12 @@ func In(needle any, array any) bool {
217217
if !n.IsValid() || n.Kind() != reflect.String {
218218
panic(fmt.Sprintf("cannot use %T as field name of %T", needle, array))
219219
}
220-
value := v.FieldByName(n.String())
221-
structValue, ok := v.Type().FieldByName(n.String())
222-
if ok && structValue.Tag.Get("expr") != "-" && value.IsValid() {
220+
field, ok := v.Type().FieldByName(n.String())
221+
if !ok || !field.IsExported() || field.Tag.Get("expr") == "-" {
222+
return false
223+
}
224+
value := v.FieldByIndex(field.Index)
225+
if value.IsValid() {
223226
return true
224227
}
225228
return false

0 commit comments

Comments
 (0)