diff --git a/ucl/builtins/lists_test.go b/ucl/builtins/lists_test.go index f3b1c7a..636a8cd 100644 --- a/ucl/builtins/lists_test.go +++ b/ucl/builtins/lists_test.go @@ -18,6 +18,7 @@ func TestLists_Add(t *testing.T) { {desc: "list add 1", eval: `lists:add [1 2 3] 4`, want: []any{1, 2, 3, 4}}, {desc: "list add 2", eval: `lists:add [1 2 3] 4 5`, want: []any{1, 2, 3, 4, 5}}, {desc: "list add 3", eval: `lists:add [1 2 3]`, want: []any{1, 2, 3}}, + {desc: "list add 4", eval: `lists:add [1 2 3] () 4 () 5`, want: []any{1, 2, 3, nil, 4, nil, 5}}, } for _, tt := range tests { diff --git a/ucl/builtins/strs.go b/ucl/builtins/strs.go index 03cd9e9..118c6a4 100644 --- a/ucl/builtins/strs.go +++ b/ucl/builtins/strs.go @@ -67,7 +67,9 @@ func join(ctx context.Context, args ucl.CallArgs) (any, error) { if i > 0 { sb.WriteString(joinStr) } - sb.WriteString(l.Index(i).String()) + if o := l.Index(i); o != nil { + sb.WriteString(o.String()) + } } return sb.String(), nil diff --git a/ucl/builtins/strs_test.go b/ucl/builtins/strs_test.go index a5d166e..b30025b 100644 --- a/ucl/builtins/strs_test.go +++ b/ucl/builtins/strs_test.go @@ -140,6 +140,7 @@ func TestStrs_Join(t *testing.T) { {desc: "join 2", eval: `strs:join ["a" "b" "c"] "\n"`, want: "a\nb\nc"}, {desc: "join 3", eval: `strs:join ["a" "b" "c"] ""`, want: "abc"}, {desc: "join 4", eval: `strs:join [] ","`, want: ""}, + {desc: "join 5", eval: `strs:join [() () () ()] ","`, want: ",,,"}, // Hmm, not super happy about this one... {desc: "join 5", eval: `strs:join ["a" "b"] ["what"]`, want: "a[what]b"},