这是indexloc提供的服务,不要输入任何密码
Skip to content

Exposing an interface will not prevent calling methods from the underlying type #744

@StarpTech

Description

@StarpTech

Hello, as titled. We figured out that the library doesn't hide methods that aren't accessible by the interface definition. We would expect that interface boundaries are enforced.

Simple example:

type Context {
	Header RequestHeaders
}
type RequestHeaders interface {
	Get(key string) string
}

Pseudocode:

code := `header.Set('foo', 'bar')`

program, err := expr.Compile(code, expr.Env(Context{}))
if err != nil {
    panic(err)
}

output, err := expr.Run(program, Context{Header: req.header})
if err != nil {
    panic(err)
}

Workaround

It looks like expr:"-"can be used as a tag to prevent exposing fields. I haven't find it in the docs unfortunately.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions