diff --git a/src/Umbraco.Infrastructure/PropertyEditors/ValueConverters/RichTextParsingRegexes.cs b/src/Umbraco.Infrastructure/PropertyEditors/ValueConverters/RichTextParsingRegexes.cs index 75851ee85619..2d4c19c17a49 100644 --- a/src/Umbraco.Infrastructure/PropertyEditors/ValueConverters/RichTextParsingRegexes.cs +++ b/src/Umbraco.Infrastructure/PropertyEditors/ValueConverters/RichTextParsingRegexes.cs @@ -4,6 +4,6 @@ namespace Umbraco.Cms.Core.PropertyEditors.ValueConverters; internal static partial class RichTextParsingRegexes { - [GeneratedRegex(".[^\"]*)\"><\\/umb-rte-block(?:-inline)?>")] + [GeneratedRegex(".[^\"]*)\">(?:)?<\\/umb-rte-block(?:-inline)?>")] public static partial Regex BlockRegex(); } diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/RichTextPropertyEditorHelperTests.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/RichTextPropertyEditorHelperTests.cs index 42bff3a868e1..71fa5f085c97 100644 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/RichTextPropertyEditorHelperTests.cs +++ b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/PropertyEditors/RichTextPropertyEditorHelperTests.cs @@ -135,7 +135,7 @@ public void Can_Parse_Blocks_With_Content_Only() { const string input = """ { - "markup": "

this is some markup

", + "markup": "

this is some markup

", "blocks": { "layout": { "Umbraco.TinyMCE": [{ @@ -157,7 +157,7 @@ public void Can_Parse_Blocks_With_Content_Only() var result = RichTextPropertyEditorHelper.TryParseRichTextEditorValue(input, JsonSerializer(), Logger(), out RichTextEditorValue? value); Assert.IsTrue(result); Assert.IsNotNull(value); - Assert.AreEqual("

this is some markup

", value.Markup); + Assert.AreEqual("

this is some markup

", value.Markup); Assert.IsNotNull(value.Blocks); @@ -172,6 +172,57 @@ public void Can_Parse_Blocks_With_Content_Only() Assert.AreEqual(0, value.Blocks.SettingsData.Count); } + [Test] + public void Can_Parse_Mixed_Blocks_And_Inline_Blocks() + { + const string input = """ + { + "markup": "

this is some markup

", + "blocks": { + "layout": { + "Umbraco.TinyMCE": [{ + "contentUdi": "umb://element/36cc710ad8a645d0a07f7bbd8742cf02" + }, { + "contentUdi": "umb://element/36cc710ad8a645d0a07f7bbd8742cf03" + } + ] + }, + "contentData": [{ + "contentTypeKey": "b2f0806c-d231-4c78-88b2-3c97d26e1123", + "udi": "umb://element/36cc710ad8a645d0a07f7bbd8742cf02", + "contentPropertyAlias": "A content property value" + }, { + "contentTypeKey": "b2f0806c-d231-4c78-88b2-3c97d26e1124", + "udi": "umb://element/36cc710ad8a645d0a07f7bbd8742cf03", + "contentPropertyAlias": "A content property value" + } + ], + "settingsData": [] + } + } + """; + + var result = RichTextPropertyEditorHelper.TryParseRichTextEditorValue(input, JsonSerializer(), Logger(), out RichTextEditorValue? value); + Assert.IsTrue(result); + Assert.IsNotNull(value); + Assert.AreEqual("

this is some markup

", value.Markup); + + Assert.IsNotNull(value.Blocks); + + Guid[] contentTypeGuids = [Guid.Parse("b2f0806c-d231-4c78-88b2-3c97d26e1123"), Guid.Parse("b2f0806c-d231-4c78-88b2-3c97d26e1124")]; + Guid[] itemGuids = [Guid.Parse("36cc710a-d8a6-45d0-a07f-7bbd8742cf02"), Guid.Parse("36cc710a-d8a6-45d0-a07f-7bbd8742cf03")]; + + Assert.AreEqual(2, value.Blocks.ContentData.Count); + for (var i = 0; i < value.Blocks.ContentData.Count; i++) { + var item = value.Blocks.ContentData[i]; + Assert.AreEqual(contentTypeGuids[i], item.ContentTypeKey); + Assert.AreEqual(new GuidUdi(Constants.UdiEntityType.Element, itemGuids[i]), item.Udi); + Assert.AreEqual(itemGuids[i], item.Key); + } + + Assert.AreEqual(0, value.Blocks.SettingsData.Count); + } + private IJsonSerializer JsonSerializer() => new SystemTextJsonSerializer(); private ILogger Logger() => Mock.Of();