diff --git a/src/modules/Elsa.Studio.UIHints/Components/MultiLine.razor b/src/modules/Elsa.Studio.UIHints/Components/MultiLine.razor index f7e48eba..ad5d76e1 100644 --- a/src/modules/Elsa.Studio.UIHints/Components/MultiLine.razor +++ b/src/modules/Elsa.Studio.UIHints/Components/MultiLine.razor @@ -1,5 +1,6 @@ @using Elsa.Studio.Models @using Elsa.Api.Client.Resources.Scripting.Models +@using Elsa.Studio.UIHints.Extensions @{ var inputDescriptor = EditorContext.InputDescriptor; @@ -29,7 +30,7 @@ private async Task OnValueChanged(string newValue) { - var expression = Expression.CreateLiteral(newValue); + var expression = Expression.CreateLiteral(newValue.TrimNull()); await EditorContext.UpdateExpressionAsync(expression); } diff --git a/src/modules/Elsa.Studio.UIHints/Components/SingleLine.razor b/src/modules/Elsa.Studio.UIHints/Components/SingleLine.razor index 83f0f62b..93e25d78 100644 --- a/src/modules/Elsa.Studio.UIHints/Components/SingleLine.razor +++ b/src/modules/Elsa.Studio.UIHints/Components/SingleLine.razor @@ -45,7 +45,7 @@ private async Task OnValueChanged(string newValue) { - var expression = Expression.CreateLiteral(newValue); + var expression = Expression.CreateLiteral(newValue.TrimWhitespace()); await EditorContext.UpdateExpressionAsync(expression); } diff --git a/src/modules/Elsa.Studio.UIHints/Extensions/StringExtensions.cs b/src/modules/Elsa.Studio.UIHints/Extensions/StringExtensions.cs new file mode 100644 index 00000000..9b57c8a1 --- /dev/null +++ b/src/modules/Elsa.Studio.UIHints/Extensions/StringExtensions.cs @@ -0,0 +1,23 @@ +namespace Elsa.Studio.UIHints.Extensions; + +/// +/// Provides a set of extension methods for . +/// +public static class StringExtensions +{ + /// + /// Trims the whitespace from the string, including null characters and new lines. + /// + public static string TrimWhitespace(this string value) + { + return value.Trim(' ', '\0', '\n', '\r'); + } + + /// + /// Trims the null characters from the string. + /// + public static string TrimNull(this string value) + { + return value.Trim('\0'); + } +} \ No newline at end of file