Fixed nil-pointer panic in strs:join
All checks were successful
Build / build (push) Successful in 2m11s

This commit is contained in:
Leon Mika 2025-02-20 21:04:01 +11:00
parent 2fbfd6d88a
commit 176b0cd83b
3 changed files with 5 additions and 1 deletions

View file

@ -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 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 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 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 { for _, tt := range tests {

View file

@ -67,7 +67,9 @@ func join(ctx context.Context, args ucl.CallArgs) (any, error) {
if i > 0 { if i > 0 {
sb.WriteString(joinStr) sb.WriteString(joinStr)
} }
sb.WriteString(l.Index(i).String()) if o := l.Index(i); o != nil {
sb.WriteString(o.String())
}
} }
return sb.String(), nil return sb.String(), nil

View file

@ -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 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 3", eval: `strs:join ["a" "b" "c"] ""`, want: "abc"},
{desc: "join 4", eval: `strs:join [] ","`, want: ""}, {desc: "join 4", eval: `strs:join [] ","`, want: ""},
{desc: "join 5", eval: `strs:join [() () () ()] ","`, want: ",,,"},
// Hmm, not super happy about this one... // Hmm, not super happy about this one...
{desc: "join 5", eval: `strs:join ["a" "b"] ["what"]`, want: "a[what]b"}, {desc: "join 5", eval: `strs:join ["a" "b"] ["what"]`, want: "a[what]b"},