diff --git a/Doppler.HtmlEditorApi.Test/Domain/DopplerHtmlDocumentTest.cs b/Doppler.HtmlEditorApi.Test/Domain/DopplerHtmlDocumentTest.cs index d8f0f356..236528dc 100644 --- a/Doppler.HtmlEditorApi.Test/Domain/DopplerHtmlDocumentTest.cs +++ b/Doppler.HtmlEditorApi.Test/Domain/DopplerHtmlDocumentTest.cs @@ -309,7 +309,7 @@ public void GetTrackableUrls_should_not_map_field_names() } [Fact] - public void SanitizeDynamicContentNode_should_modify_html_dynamic_content_when_has_two_or_more_child_node_and_replace_image_src() + public void SanitizeDynamicContentNodes_should_modify_html_dynamic_content_when_has_two_or_more_child_node_and_replace_image_src() { // Arrange var input = $@" @@ -361,7 +361,7 @@ public void SanitizeDynamicContentNode_should_modify_html_dynamic_content_when_h "; // Act - htmlDocument.SanitizeDynamicContentNode(); + htmlDocument.SanitizeDynamicContentNodes(); var content = htmlDocument.GetDopplerContent(); // Assert diff --git a/Doppler.HtmlEditorApi/Controllers/CampaignsController.cs b/Doppler.HtmlEditorApi/Controllers/CampaignsController.cs index d6dbaa0d..b1e03165 100644 --- a/Doppler.HtmlEditorApi/Controllers/CampaignsController.cs +++ b/Doppler.HtmlEditorApi/Controllers/CampaignsController.cs @@ -236,7 +236,7 @@ private async Task ExtractHtmlDomFromCampaignContent(string htmlDocument.ReplaceFieldNameTagsByFieldIdTags(dopplerFieldsProcessor.GetFieldIdOrNull); htmlDocument.RemoveUnknownFieldIdTags(dopplerFieldsProcessor.FieldIdExist); htmlDocument.SanitizeTrackableLinks(); - htmlDocument.SanitizeDynamicContentNode(); + htmlDocument.SanitizeDynamicContentNodes(); return htmlDocument; } diff --git a/Doppler.HtmlEditorApi/Domain/DopplerHtmlDocument.cs b/Doppler.HtmlEditorApi/Domain/DopplerHtmlDocument.cs index 8e95f057..f9ac2bf1 100644 --- a/Doppler.HtmlEditorApi/Domain/DopplerHtmlDocument.cs +++ b/Doppler.HtmlEditorApi/Domain/DopplerHtmlDocument.cs @@ -94,22 +94,24 @@ public void SanitizeTrackableLinks() /// - Remove repeated cart item tags /// - Replace img src value by [[[DC:IMAGE]]] /// - public void SanitizeDynamicContentNode() + public void SanitizeDynamicContentNodes() { - var dynamicContentNode = _contentNode.SelectSingleNode("//dynamiccontent"); - if (dynamicContentNode != null) + var dynamicContentNodes = _contentNode.SelectNodes("//dynamiccontent"); + if (dynamicContentNodes != null) { - var divNodes = dynamicContentNode.SelectNodes("div"); - if (divNodes != null && divNodes.Count > 1) + for (var i = 0; i < dynamicContentNodes.Count; i++) { - for (var i = 1; i < divNodes.Count; i++) + var divNodes = dynamicContentNodes[i].SelectNodes("div"); + if (divNodes != null && divNodes.Count > 1) { - dynamicContentNode.RemoveChild(divNodes[i]); + for (var j = 1; j < divNodes.Count; j++) + { + dynamicContentNodes[i].RemoveChild(divNodes[j]); + } } + var imgNode = dynamicContentNodes[i].SelectSingleNode(".//img"); + imgNode?.SetAttributeValue("src", "[[[DC:IMAGE]]]"); } - - var imgNode = dynamicContentNode.SelectSingleNode(".//img"); - imgNode?.SetAttributeValue("src", "[[[DC:IMAGE]]]"); } }