Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion libraries/AdaptiveExpressions/BuiltinFunctions/Join.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Collections;
using System.Linq;
using AdaptiveExpressions.Memory;
using Newtonsoft.Json.Linq;

namespace AdaptiveExpressions.BuiltinFunctions
{
Expand Down Expand Up @@ -34,7 +35,11 @@ private static (object value, string error) EvalJoin(Expression expression, IMem
{
if (args.Count == 2)
{
result = string.Join(args[1].ToString(), list.OfType<object>().Select(x => x.ToString()));
result = string.Join(
args[1].ToString(),
list.OfType<object>()
.SelectMany(x => x is IEnumerable arr && x is not string && x is not JToken ? arr.Cast<object>() : new[] { x })
.Select(x => x?.ToString() ?? string.Empty));
}
else
{
Expand Down
1 change: 1 addition & 0 deletions tests/AdaptiveExpressions.Tests/ExpressionParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,7 @@ public class ExpressionParserTests
Test("join(createArray('a', 'b', 'c'), ',', ' and ')", "a,b and c"),
Test("join(createArray('a', 'b'), ',', ' and ')", "a and b"),
Test("join(createArray(\r\n'a',\r\n 'b'), ','\r\n,\r\n ' and ')", "a and b"),
Test("join(createArray(['a'], ['b'], ['c']), ',')", "a,b,c"),
Test("join(foreach(dialog, item, item.key), ',')", "x,instance,options,title,subTitle"),
Test("join(foreach(dialog, item => item.key), ',')", "x,instance,options,title,subTitle"),
Test("foreach(dialog, item, item.value)[1].xxx", "instance"),
Expand Down