diff --git a/internal/lang/marks/paths.go b/internal/lang/marks/paths.go index 97120602a5..0bb81ae43b 100644 --- a/internal/lang/marks/paths.go +++ b/internal/lang/marks/paths.go @@ -31,9 +31,12 @@ func PathsWithMark(pvms []cty.PathValueMarks, wantMark any) (withWanted []cty.Pa if _, ok := pvm.Marks[wantMark]; ok { withWanted = append(withWanted, pvm.Path) } + for mark := range pvm.Marks { if mark != wantMark { withOthers = append(withOthers, pvm) + // only add a path with unwanted marks a single time + break } } } diff --git a/internal/lang/marks/paths_test.go b/internal/lang/marks/paths_test.go index ed4db941c7..f6adf437e3 100644 --- a/internal/lang/marks/paths_test.go +++ b/internal/lang/marks/paths_test.go @@ -16,7 +16,7 @@ func TestPathsWithMark(t *testing.T) { input := []cty.PathValueMarks{ { Path: cty.GetAttrPath("sensitive"), - Marks: cty.NewValueMarks(Sensitive), + Marks: cty.NewValueMarks("sensitive"), }, { Path: cty.GetAttrPath("other"), @@ -24,11 +24,15 @@ func TestPathsWithMark(t *testing.T) { }, { Path: cty.GetAttrPath("both"), - Marks: cty.NewValueMarks(Sensitive, "other"), + Marks: cty.NewValueMarks("sensitive", "other"), + }, + { + Path: cty.GetAttrPath("neither"), + Marks: cty.NewValueMarks("x", "y"), }, } - gotPaths, gotOthers := PathsWithMark(input, Sensitive) + gotPaths, gotOthers := PathsWithMark(input, "sensitive") wantPaths := []cty.Path{ cty.GetAttrPath("sensitive"), cty.GetAttrPath("both"), @@ -40,7 +44,7 @@ func TestPathsWithMark(t *testing.T) { }, { Path: cty.GetAttrPath("both"), - Marks: cty.NewValueMarks(Sensitive, "other"), + Marks: cty.NewValueMarks("sensitive", "other"), // Note that this intentionally preserves the fact that the // attribute was both sensitive _and_ had another mark, since // that gives the caller the most possible information to @@ -48,6 +52,10 @@ func TestPathsWithMark(t *testing.T) { // an error message, or whatever. It also conveniently avoids // allocating a new mark set, which is nice. }, + { + Path: cty.GetAttrPath("neither"), + Marks: cty.NewValueMarks("x", "y"), + }, } if diff := cmp.Diff(wantPaths, gotPaths, ctydebug.CmpOptions); diff != "" {