adobe / acc-js-sdk

A JavaScript SDK for Adobe Campaign Classic
Apache License 2.0
21 stars 22 forks source link

Consider elements with multiple text children as if they had one single text child #85

Closed mkiki closed 1 year ago

mkiki commented 1 year ago

Description

The content of HTML deliveries is returned as an XML CDATA node. Sometimes this content itself may contain CDATA elements. Campaign will "escape" such content as follow:

  /*<![CDATA[*/ @import url("https://fonts.googleapis.com/css?family=Lato|Open+Sans");[style*="Lato"]{font-family:Lato,Arial,sans-serif!important}[style*="Open Sans"]{font-family:Open Sans,Arial,sans-serif!important}/*]]]><![CDATA[]>*/

When the SDK tried to convert XML to JSON, it has the following logic:

In our delivery content example, the /<![CDATA[/ and /]]]><![CDATA[]>/ escaping is a hack which actually splits the content into 2 CDATA elements. So when it's used, the delivery content will be returned as "source": { "$": content } instead of "$source": content.

This PR changes the behavior by changing the rule (2) above as follow: if a XML element has multiple children which are all text or cdata nodes, it will use the "$property" syntax instead of "$" property syntax. For the delivery content example, it means that it will always return "$source": content.

Related Issue

Acrite email editor could not process content containing escape CDATA elements (usually coming from ACS) because the it expects the content to be available in "content.html.$source" property and not "content.html.source.$"

Motivation and Context

All types of content should be returned consistently (i.e. with same syntax) by the SDK

How Has This Been Tested?

New unit tests

Types of changes

Limited risk of breaking things as we are changing the structure of the returned JSON in some edge cases.

Checklist: