diff --git a/libraries/AdaptiveExpressions/BuiltinFunctions/Bool.cs b/libraries/AdaptiveExpressions/BuiltinFunctions/Bool.cs index c57e732849..7ed30c7fbb 100644 --- a/libraries/AdaptiveExpressions/BuiltinFunctions/Bool.cs +++ b/libraries/AdaptiveExpressions/BuiltinFunctions/Bool.cs @@ -1,7 +1,9 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +using System; using System.Collections.Generic; +using System.Globalization; namespace AdaptiveExpressions.BuiltinFunctions { @@ -29,6 +31,18 @@ private static bool Function(IReadOnlyList args) arg = @int != 0; } + if (arg is string @string) + { + try + { + arg = Convert.ToBoolean(@string, CultureInfo.InvariantCulture); + } + catch (FormatException) + { + // Any string other than 'true' or 'false' will throw an exception. We'll ignore them. + } + } + return FunctionUtils.IsLogicTrue(arg); } } diff --git a/tests/AdaptiveExpressions.Tests/ExpressionParserTests.cs b/tests/AdaptiveExpressions.Tests/ExpressionParserTests.cs index b33267a716..ef909760e0 100644 --- a/tests/AdaptiveExpressions.Tests/ExpressionParserTests.cs +++ b/tests/AdaptiveExpressions.Tests/ExpressionParserTests.cs @@ -734,7 +734,8 @@ public class ExpressionParserTests Test("bool(0)", false), Test("bool(null)", false), Test("bool(hello * 5)", false), - Test("bool('false')", true), + Test("bool('false')", false), + Test("bool('true')", true), Test("bool('hi')", true), Test("[1,2,3]", new List { 1, 2, 3 }), Test("[1,2,3, [4,5]]", new List { 1, 2, 3, new List { 4, 5 } }),