diff --git a/libraries/AdaptiveExpressions/ExpressionFunctions.cs b/libraries/AdaptiveExpressions/ExpressionFunctions.cs index 6453ebb43d..0e253c0e06 100644 --- a/libraries/AdaptiveExpressions/ExpressionFunctions.cs +++ b/libraries/AdaptiveExpressions/ExpressionFunctions.cs @@ -3118,21 +3118,36 @@ private static IDictionary GetStandardFunctions() // String new ExpressionEvaluator( ExpressionType.Concat, - Apply( + ApplySequence( args => { - var builder = new StringBuilder(); - foreach (var arg in args) + var firstItem = args[0]; + var secondItem = args[1]; + var isFirstList = TryParseList(firstItem, out var firstList); + var isSecondList = TryParseList(secondItem, out var secondList); + + if (firstItem == null && secondItem == null) { - if (arg != null) - { - builder.Append(arg.ToString()); - } + return null; + } + else if (firstItem == null && isSecondList) + { + return secondList; + } + else if (secondItem == null && isFirstList) + { + return firstList; + } + else if (isFirstList && isSecondList) + { + return firstList.OfType().Concat(secondList.OfType()).ToList(); + } + else + { + return $"{firstItem?.ToString()}{secondItem?.ToString()}"; } - - return builder.ToString(); }), - ReturnType.String, + ReturnType.Array | ReturnType.String, ValidateAtLeastOne), new ExpressionEvaluator( ExpressionType.Length, diff --git a/tests/AdaptiveExpressions.Tests/ExpressionParserTests.cs b/tests/AdaptiveExpressions.Tests/ExpressionParserTests.cs index fe8edde863..2cbe65c333 100644 --- a/tests/AdaptiveExpressions.Tests/ExpressionParserTests.cs +++ b/tests/AdaptiveExpressions.Tests/ExpressionParserTests.cs @@ -813,6 +813,9 @@ public class ExpressionParserTests Test("contains(items, 'hi')", false), Test("contains(bag, 'three')", true), Test("contains(bag, 'xxx')", false), + Test("concat(null, [1, 2], null)", new List { 1, 2 }), + Test("concat(createArray(1, 2), createArray(3, 4))", new List { 1, 2, 3, 4 }), + Test("concat(['a', 'b'], ['b', 'c'], ['c', 'd'])", new List { "a", "b", "b", "c", "c", "d" }), Test("count(split(hello,'e'))", 2), Test("count(createArray('h', 'e', 'l', 'l', 'o'))", 5), Test("empty('')", true),