Skip to content

Commit 7c3da5e

Browse files
committed
backport of commit 64c68a0
1 parent cdc410f commit 7c3da5e

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

internal/lang/marks/paths.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,12 @@ func PathsWithMark(pvms []cty.PathValueMarks, wantMark any) (withWanted []cty.Pa
3030
if _, ok := pvm.Marks[wantMark]; ok {
3131
withWanted = append(withWanted, pvm.Path)
3232
}
33+
3334
for mark := range pvm.Marks {
3435
if mark != wantMark {
3536
withOthers = append(withOthers, pvm)
37+
// only add a path with unwanted marks a single time
38+
break
3639
}
3740
}
3841
}

internal/lang/marks/paths_test.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,23 @@ func TestPathsWithMark(t *testing.T) {
1616
input := []cty.PathValueMarks{
1717
{
1818
Path: cty.GetAttrPath("sensitive"),
19-
Marks: cty.NewValueMarks(Sensitive),
19+
Marks: cty.NewValueMarks("sensitive"),
2020
},
2121
{
2222
Path: cty.GetAttrPath("other"),
2323
Marks: cty.NewValueMarks("other"),
2424
},
2525
{
2626
Path: cty.GetAttrPath("both"),
27-
Marks: cty.NewValueMarks(Sensitive, "other"),
27+
Marks: cty.NewValueMarks("sensitive", "other"),
28+
},
29+
{
30+
Path: cty.GetAttrPath("neither"),
31+
Marks: cty.NewValueMarks("x", "y"),
2832
},
2933
}
3034

31-
gotPaths, gotOthers := PathsWithMark(input, Sensitive)
35+
gotPaths, gotOthers := PathsWithMark(input, "sensitive")
3236
wantPaths := []cty.Path{
3337
cty.GetAttrPath("sensitive"),
3438
cty.GetAttrPath("both"),
@@ -40,14 +44,18 @@ func TestPathsWithMark(t *testing.T) {
4044
},
4145
{
4246
Path: cty.GetAttrPath("both"),
43-
Marks: cty.NewValueMarks(Sensitive, "other"),
47+
Marks: cty.NewValueMarks("sensitive", "other"),
4448
// Note that this intentionally preserves the fact that the
4549
// attribute was both sensitive _and_ had another mark, since
4650
// that gives the caller the most possible information to
4751
// potentially handle this combination in a special way in
4852
// an error message, or whatever. It also conveniently avoids
4953
// allocating a new mark set, which is nice.
5054
},
55+
{
56+
Path: cty.GetAttrPath("neither"),
57+
Marks: cty.NewValueMarks("x", "y"),
58+
},
5159
}
5260

5361
if diff := cmp.Diff(wantPaths, gotPaths, ctydebug.CmpOptions); diff != "" {

0 commit comments

Comments
 (0)