adobe / acc-js-sdk

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

Fixed a bug causing incorrect JSON to XML transformation when the JSON object has a property named 'length' #84

Closed mkiki closed 1 year ago

mkiki commented 1 year ago

Description

Fixed a bug causing incorrect JSON to XML transformation when the JON object has a property named 'length'

Related Issue

In the following JSON object, there's an "attribute" object with a property named "length"

            const json = {
                element: {
                  attribute: {
                    length: "256",
                    name: "id",
                  },
              }
            };

Converting such an object to XML fails or does not return the expected result because an internal conversion function uses the existence of the "length" property to test if a JS object is an array In this example, "attribute" is considered an array since it has a "length" attribute. However, in this case "length" is just an XTK attribute which happens to be named 'length'. This attribute exists on schemas for example.

Now using Array.isArray javaScript function to safely test the type of an object to be an array.

Motivation and Context

Bug fix discovered during implementation of https://github.com/adobe/acc-js-sdk/pull/80

How Has This Been Tested?

New unit test which was failing before and is now successful

Types of changes

Checklist: