Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions builtin/builtin.go
Original file line number Diff line number Diff line change
Expand Up @@ -814,10 +814,10 @@ var Builtins = []*Function{
if v.Kind() != reflect.Map {
return nil, fmt.Errorf("cannot get values from %s", v.Kind())
}
keys := v.MapKeys()
out := make([]any, len(keys))
for i, key := range keys {
out[i] = v.MapIndex(key).Interface()
out := make([]any, v.Len())
iter := v.MapRange()
for i := 0; iter.Next(); i++ {
out[i] = iter.Value().Interface()
}
return out, nil
},
Expand Down
10 changes: 10 additions & 0 deletions builtin/builtin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,16 @@ func TestBuiltin(t *testing.T) {
}
}

func TestBuiltin_values_nan_key(t *testing.T) {
env := map[string]any{
"m": map[float64]string{math.NaN(): "saved"},
}

out, err := expr.Eval("values(m)", env)
require.NoError(t, err)
assert.Equal(t, []any{"saved"}, out)
}

func TestBuiltin_get_struct_non_string_key(t *testing.T) {
type anyEnv struct{ Foo any }
env := anyEnv{Foo: mock.Foo{Value: "a"}}
Expand Down