Skip to content

Operator "in" can see unexported struct fields #807

@diegommm

Description

@diegommm

Example (Go Playground):

package main

import (
	"fmt"

	"github.com/expr-lang/expr"
)

func main() {
	type MyStruct struct {
		nonExported string
	}
	fmt.Println(expr.Eval(` "nonExported" in $env `, MyStruct{})) // "in" can see unexported fields
	fmt.Println(expr.Eval(` nonExported `, MyStruct{}))           // trying to access them fails as expected
}

I would expect that "in" returns false when testing an unexported struct field. This can be a problem for a number of reasons:

  1. It is confusing if I can see the field with the "in" operator but cannot access it with a member operator.
  2. This can be disclosing the existence of information that we want to keep private, thus we make the field unexported.

P.S.: I know where the bug is and can provide a PR to fix it, but I'm not creating it right now because I've been creating too many issues and PRs these last days. I would like your confirmation before proceeding to avoid bugging you if you don't have time. Let me know and I can work in the bug fix.

Thank you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions