From f8a6f66be436b454179fa2d679b5a5d0c927a2e8 Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Thu, 7 Feb 2019 14:35:13 -0800 Subject: [PATCH] lang/funcs: Fix panic in "join" when an element is null It is now a proper error message. --- lang/funcs/string.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lang/funcs/string.go b/lang/funcs/string.go index cb3d03cbd4..c9ddf19e36 100644 --- a/lang/funcs/string.go +++ b/lang/funcs/string.go @@ -39,10 +39,18 @@ var JoinFunc = function.New(&function.Spec{ } items := make([]string, 0, l) - for _, list := range listVals { + for ai, list := range listVals { + ei := 0 for it := list.ElementIterator(); it.Next(); { _, val := it.Element() + if val.IsNull() { + if len(listVals) > 1 { + return cty.UnknownVal(cty.String), function.NewArgErrorf(ai+1, "element %d of list %d is null; cannot concatenate null values", ei, ai+1) + } + return cty.UnknownVal(cty.String), function.NewArgErrorf(ai+1, "element %d is null; cannot concatenate null values", ei) + } items = append(items, val.AsString()) + ei++ } }