From 0fc271f4d98635c818ee4b7ef31c00b410fc22a6 Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Thu, 11 Jun 2020 09:17:28 -0700 Subject: [PATCH 1/8] Prepare for a later v1.5.1 release --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e30aea..f74a708 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +# 1.5.1 (Unreleased) + + # 1.5.0 (March 17, 2025) * `cty`: New `Value.HasWhollyKnownType` method, for testing whether a value's type could potentially change if any unknown values it was constructed from were to become known. ([#55](https://github.com/zclconf/go-cty/pull/55)) From c361d2e82c0e71fdd9a3c5178529d430137b85ae Mon Sep 17 00:00:00 2001 From: Pam Selle Date: Tue, 23 Jun 2020 13:35:05 -0400 Subject: [PATCH 2/8] function/stdlib: Allow empty maps in merge function --- cty/function/stdlib/collection.go | 3 +++ cty/function/stdlib/collection_test.go | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/cty/function/stdlib/collection.go b/cty/function/stdlib/collection.go index a2d1349..cfa8c94 100644 --- a/cty/function/stdlib/collection.go +++ b/cty/function/stdlib/collection.go @@ -762,6 +762,9 @@ var MergeFunc = function.New(&function.Spec{ case allNull: return cty.NullVal(retType), nil case retType.IsMapType(): + if len(outputMap) == 0 { + return cty.MapValEmpty(retType.ElementType()), nil + } return cty.MapVal(outputMap), nil case retType.IsObjectType(), retType.Equals(cty.DynamicPseudoType): return cty.ObjectVal(outputMap), nil diff --git a/cty/function/stdlib/collection_test.go b/cty/function/stdlib/collection_test.go index 96c1c89..f2dd4f2 100644 --- a/cty/function/stdlib/collection_test.go +++ b/cty/function/stdlib/collection_test.go @@ -506,6 +506,14 @@ func TestMerge(t *testing.T) { cty.NilVal, true, }, + { // Empty maps are allowed in merge + []cty.Value{ + cty.MapValEmpty(cty.String), + cty.MapValEmpty(cty.String), + }, + cty.MapValEmpty(cty.String), + false, + }, } for _, test := range tests { From 7403df99ba21792757382d92c6916a9327975038 Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Tue, 23 Jun 2020 10:36:30 -0700 Subject: [PATCH 3/8] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f74a708..b43785b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ # 1.5.1 (Unreleased) +* `function/stdlib`: The `merge` function will no longer panic if all given maps are empty. ([#58](https://github.com/zclconf/go-cty/pull/58)) # 1.5.0 (March 17, 2025) From 927a6f952cb9e430924cdc7cbcfc99743ef6cb40 Mon Sep 17 00:00:00 2001 From: Alisdair McDiarmid Date: Mon, 22 Jun 2020 17:20:31 -0400 Subject: [PATCH 4/8] function/stdlib: Fix panic with unknown set values The fix for set unification recently introduced a bug with unknown set values which would cause a panic. This was triggered by calling LengthInt on an unknown collection. This commit fixes this by first verifying that the argument is known, so that calling its length is safe. If the argument is not known, it could be of any length, so we do not want to omit its element type from the set to be unified. Includes regression tests. --- cty/function/stdlib/set.go | 2 +- cty/function/stdlib/set_test.go | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/cty/function/stdlib/set.go b/cty/function/stdlib/set.go index f24b5f2..6e3e5ae 100644 --- a/cty/function/stdlib/set.go +++ b/cty/function/stdlib/set.go @@ -167,7 +167,7 @@ func setOperationReturnType(args []cty.Value) (ret cty.Type, err error) { // Do not unify types for empty dynamic pseudo typed collections. These // will always convert to any other concrete type. - if arg.LengthInt() == 0 && ty.Equals(cty.DynamicPseudoType) { + if arg.IsKnown() && arg.LengthInt() == 0 && ty.Equals(cty.DynamicPseudoType) { continue } diff --git a/cty/function/stdlib/set_test.go b/cty/function/stdlib/set_test.go index 34494da..a9af3fb 100644 --- a/cty/function/stdlib/set_test.go +++ b/cty/function/stdlib/set_test.go @@ -76,6 +76,13 @@ func TestSetUnion(t *testing.T) { }, cty.SetValEmpty(cty.DynamicPseudoType), }, + { + []cty.Value{ + cty.SetVal([]cty.Value{cty.StringVal("5")}), + cty.UnknownVal(cty.Set(cty.Number)), + }, + cty.UnknownVal(cty.Set(cty.String)), + }, } for _, test := range tests { @@ -159,6 +166,13 @@ func TestSetIntersection(t *testing.T) { }, cty.SetValEmpty(cty.DynamicPseudoType), }, + { + []cty.Value{ + cty.SetVal([]cty.Value{cty.StringVal("5")}), + cty.UnknownVal(cty.Set(cty.Number)), + }, + cty.UnknownVal(cty.Set(cty.String)), + }, } for _, test := range tests { @@ -226,6 +240,11 @@ func TestSetSubtract(t *testing.T) { cty.SetValEmpty(cty.DynamicPseudoType), cty.SetValEmpty(cty.DynamicPseudoType), }, + { + cty.SetVal([]cty.Value{cty.StringVal("5")}), + cty.UnknownVal(cty.Set(cty.Number)), + cty.UnknownVal(cty.Set(cty.String)), + }, } for _, test := range tests { From a2906bab8b4ce2b245123f38c559765ab5024118 Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Tue, 23 Jun 2020 10:44:24 -0700 Subject: [PATCH 5/8] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b43785b..06adaae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # 1.5.1 (Unreleased) * `function/stdlib`: The `merge` function will no longer panic if all given maps are empty. ([#58](https://github.com/zclconf/go-cty/pull/58)) +* `function/stdlib`: The various set-manipulation functions, like `setunion`, will no longer panic if given an unknown set value. ([#59](https://github.com/zclconf/go-cty/pull/59)) # 1.5.0 (March 17, 2025) From d132313fc696b1017024b3c85b07ad5513698f79 Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Thu, 25 Jun 2020 13:56:47 -0700 Subject: [PATCH 6/8] v1.5.1 --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 06adaae..ebc2316 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -# 1.5.1 (Unreleased) +# 1.5.1 (June 25, 2020) * `function/stdlib`: The `merge` function will no longer panic if all given maps are empty. ([#58](https://github.com/zclconf/go-cty/pull/58)) * `function/stdlib`: The various set-manipulation functions, like `setunion`, will no longer panic if given an unknown set value. ([#59](https://github.com/zclconf/go-cty/pull/59)) From 877adfd5e0a1a3b1b95efdf707269bf838aaba29 Mon Sep 17 00:00:00 2001 From: Baraa Basata Date: Tue, 18 Mar 2025 09:50:11 -0400 Subject: [PATCH 7/8] Update CHANGELOG.md --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ebc2316..f6bff53 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -# 1.5.1 (June 25, 2020) +# 1.5.1 (Unreleased) * `function/stdlib`: The `merge` function will no longer panic if all given maps are empty. ([#58](https://github.com/zclconf/go-cty/pull/58)) * `function/stdlib`: The various set-manipulation functions, like `setunion`, will no longer panic if given an unknown set value. ([#59](https://github.com/zclconf/go-cty/pull/59)) @@ -8,7 +8,7 @@ * `cty`: New `Value.HasWhollyKnownType` method, for testing whether a value's type could potentially change if any unknown values it was constructed from were to become known. ([#55](https://github.com/zclconf/go-cty/pull/55)) * `convert`: Fix incorrect panic when converting a tuple with a dynamic-typed null member into a list or set, due to overly-liberal type unification. ([#56](https://github.com/zclconf/go-cty/pull/56)) -# 1.4.2 (Unreleased) +# 1.4.2 * `function/stdlib`: The `jsonencode` function will now correctly accept a null as its argument, and produce the JSON representation `"null"` rather than returning an error. ([#54](https://github.com/zclconf/go-cty/pull/54)) * `convert`: Don't panic when asked to convert a tuple of objects to a list type constraint containing a nested `cty.DynamicPseudoType`. ([#53](https://github.com/zclconf/go-cty/pull/53)) From 0e0bec9835b7595d0ab102a77e660e0d4f72047f Mon Sep 17 00:00:00 2001 From: Baraa Basata Date: Tue, 18 Mar 2025 10:21:26 -0400 Subject: [PATCH 8/8] go mod tidy --- go.mod | 2 -- go.sum | 27 ++++++++++++++++++++++----- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/go.mod b/go.mod index 882066f..9cdd5f4 100644 --- a/go.mod +++ b/go.mod @@ -6,8 +6,6 @@ require ( github.com/google/go-cmp v0.3.1 github.com/kr/pretty v0.1.0 // indirect github.com/vmihailenco/msgpack v3.3.3+incompatible - golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 // indirect - golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f // indirect golang.org/x/text v0.3.8 google.golang.org/appengine v1.1.0 // indirect gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect diff --git a/go.sum b/go.sum index 0231048..5773695 100644 --- a/go.sum +++ b/go.sum @@ -11,16 +11,33 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/vmihailenco/msgpack v3.3.3+incompatible h1:wapg9xDUZDzGCNFlwc5SqI1rvcciqcxEHac4CYj89xI= github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 h1:0GoQqolDA55aaLxZyTzK/Y2ePZzZTUrRacwib7cNsYQ= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f h1:wMNYb4v58l5UBM7MYRLPG6ZhfOqbKu7X5eyFl8ZhKvA= -golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b h1:PxfKdU9lEEDYjdIzOtC4qFWgkU2rGHdKlKowJSMN9h0= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 h1:uVc8UZUe6tr40fFVnUP5Oj+veunVezqYl9z7DYw9xzw= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.3.8 h1:nAL+RVCQ9uMn3vJZbV+MRnydTJFPf8qqY42YiA6MrqY= +golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/appengine v1.1.0 h1:igQkv0AAhEIvTEpD5LIpAfav2eeVO9HBTjvKHVJPRSs= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=