Skip to content

Commit

Permalink
cty: handle deep marks in Equals
Browse files Browse the repository at this point in the history
Equals need to extract all marks from nested values, rather than just
the top level to avoid panicking during comparison.
  • Loading branch information
jbardin authored and apparentlymart committed Jul 19, 2021
1 parent 8fee7bd commit 9d6e7fe
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
6 changes: 3 additions & 3 deletions cty/value_ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ func (val Value) GoString() string {
// Use RawEquals to compare if two values are equal *ignoring* the
// short-circuit rules and the exception for null values.
func (val Value) Equals(other Value) Value {
if val.IsMarked() || other.IsMarked() {
val, valMarks := val.Unmark()
other, otherMarks := other.Unmark()
if val.ContainsMarked() || other.ContainsMarked() {
val, valMarks := val.UnmarkDeep()
other, otherMarks := other.UnmarkDeep()
return val.Equals(other).WithMarks(valMarks, otherMarks)
}

Expand Down
10 changes: 10 additions & 0 deletions cty/value_ops_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,16 @@ func TestValueEquals(t *testing.T) {
StringVal("b").Mark(2),
False.WithMarks(NewValueMarks(1, 2)),
},

{
MapVal(map[string]Value{
"a": StringVal("a").Mark("boop"),
}),
MapVal(map[string]Value{
"a": StringVal("a").Mark("blop"),
}),
True.WithMarks(NewValueMarks("boop", "blop")),
},
}

for _, test := range tests {
Expand Down

0 comments on commit 9d6e7fe

Please sign in to comment.