From fd7778320a9694c83bb638b18da002d7189b7460 Mon Sep 17 00:00:00 2001 From: Ronald Barendse Date: Tue, 13 Dec 2022 13:32:14 +0100 Subject: [PATCH] Save using consistent newline and support parsing different newlines (#13569) --- .../MultipleTextStringPropertyEditor.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Umbraco.Infrastructure/PropertyEditors/MultipleTextStringPropertyEditor.cs b/src/Umbraco.Infrastructure/PropertyEditors/MultipleTextStringPropertyEditor.cs index 4f25a54162..e21d43e996 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/MultipleTextStringPropertyEditor.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/MultipleTextStringPropertyEditor.cs @@ -68,6 +68,9 @@ public class MultipleTextStringPropertyEditor : DataEditor /// internal class MultipleTextStringPropertyValueEditor : DataValueEditor { + private static readonly string NewLine = "\n"; + private static readonly string[] NewLineDelimiters = { "\r\n", "\r", "\n" }; + private readonly ILocalizedTextService _localizedTextService; public MultipleTextStringPropertyValueEditor( @@ -119,10 +122,10 @@ public class MultipleTextStringPropertyEditor : DataEditor // only allow the max if over 0 if (max > 0) { - return string.Join(Environment.NewLine, array.Take(max)); + return string.Join(NewLine, array.Take(max)); } - return string.Join(Environment.NewLine, array); + return string.Join(NewLine, array); } /// @@ -131,7 +134,6 @@ public class MultipleTextStringPropertyEditor : DataEditor /// cannot have 2 way binding, so to get around that each item in the array needs to be an object with a string. /// /// - /// /// /// /// @@ -141,8 +143,9 @@ public class MultipleTextStringPropertyEditor : DataEditor public override object ToEditor(IProperty property, string? culture = null, string? segment = null) { var val = property.GetValue(culture, segment); - return val?.ToString()?.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries) - .Select(x => JObject.FromObject(new { value = x })) ?? new JObject[] { }; + + return val?.ToString()?.Split(NewLineDelimiters, StringSplitOptions.None).Select(x => JObject.FromObject(new { value = x })) + ?? Array.Empty(); } }