Skip to content

Any way to enforce strict mode on all maps by default? #932

@ar-sematell

Description

@ar-sematell

I'm handling a dynamic env, which is represented by a map[string]any.
When using expr.Env, it only enforces the strict mode to the immediate map, but not any nested maps.
I want to enforce that any path or reference to this dynamic environment is accessible and valid, pretty much like a strict validation.

  • Only allow accessing existing variables and their nested attributes, erroring otherwise, like in the existing expr.Env behavior
  • Only allow accessing slice indexes that are given in the expr.Env or any nested attribute

Example:

// This compiles without error, but should error:
_, err := expr.Compile(`var1.attr2`,
	expr.Env(map[string]any{
		"var1": map[string]any{
			"attr1": 1,
		},
	}),
)
require.Error(t, err)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions