From 9d6e7fe69660636bcd874766aa48e0806ab4e289 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Mon, 19 Jul 2021 16:01:27 -0400 Subject: [PATCH] cty: handle deep marks in Equals Equals need to extract all marks from nested values, rather than just the top level to avoid panicking during comparison. --- cty/value_ops.go | 6 +++--- cty/value_ops_test.go | 10 ++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/cty/value_ops.go b/cty/value_ops.go index 8c37535c..17afd8d8 100644 --- a/cty/value_ops.go +++ b/cty/value_ops.go @@ -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) } diff --git a/cty/value_ops_test.go b/cty/value_ops_test.go index 4261a35d..c6f8b94d 100644 --- a/cty/value_ops_test.go +++ b/cty/value_ops_test.go @@ -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 {