@adobe/acc-js-sdk 1.1.27 → 1.1.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,6 +3,14 @@ layout: page
3
3
  title: Change Log
4
4
  ---
5
5
 
6
+ <section class="changelog"><h1>Version 1.1.28</h1>
7
+ <h2>2023/06/09</h2>
8
+ <li>
9
+ Consider elements with multiple text children as if they had one single text child
10
+ </li>
11
+ </section>
12
+
13
+
6
14
  <section class="changelog"><h1>Version 1.1.27</h1>
7
15
  <h2>2023/05/10</h2>
8
16
  <li>
package/package-lock.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@adobe/acc-js-sdk",
3
- "version": "1.1.27",
3
+ "version": "1.1.28",
4
4
  "lockfileVersion": 2,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@adobe/acc-js-sdk",
9
- "version": "1.1.27",
9
+ "version": "1.1.28",
10
10
  "license": "ISC",
11
11
  "dependencies": {
12
12
  "axios": "^1.2.1",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/acc-js-sdk",
3
- "version": "1.1.27",
3
+ "version": "1.1.28",
4
4
  "description": "ACC Javascript SDK",
5
5
  "main": "src/index.js",
6
6
  "homepage": "https://github.com/adobe/acc-js-sdk#readme",
package/src/domUtil.js CHANGED
@@ -380,13 +380,22 @@ class DomUtil {
380
380
  return doc;
381
381
  }
382
382
 
383
+ // Get the text of a node. Will return the text if the xml node contains
384
+ // only text and cdata nodes. Otherwise will return null
383
385
  static _getTextIfTextNode(xml) {
384
- const child = xml.firstChild;
386
+ let child = xml.firstChild;
385
387
  if (!child) return null; // no children
386
388
  if (xml.hasAttributes()) return null; // no attributes
387
- if (child.nextSibling) return null; // more than 1 child
388
- if (child.nodeType !== 3 && child.nodeType !== 4) return null;
389
- const text = child.nodeValue;
389
+ let text = "";
390
+ while (child) {
391
+ // if child node is not text or cdata, it means we have a mix
392
+ // of text children and non-text children => we do not consider
393
+ // the xml node to be a text-only node
394
+ if (child.nodeType !== 3 && child.nodeType !== 4)
395
+ return null;
396
+ text = text + child.nodeValue;
397
+ child = child.nextSibling;
398
+ }
390
399
  return text;
391
400
  }
392
401
 
@@ -958,4 +958,21 @@ describe('DomUtil', function() {
958
958
  expect(new XPathElement(".").isParent()).toBe(false);
959
959
  })
960
960
  });
961
+
962
+ it("Should handle content made of CDATA text", () => {
963
+ const xml = DomUtil.parse(`<delivery>
964
+ <source><![CDATA[<head></head>]]></source>
965
+ </delivery>`);
966
+ const json = DomUtil.toJSON(xml, "SimpleJson");
967
+ expect(json.$source).toBe("<head></head>")
968
+ });
969
+ it("Should handle content made of multiple CDATA text", () => {
970
+ const xml = DomUtil.parse(`<delivery>
971
+ <source><![CDATA[<head>]]><![CDATA[</head>]]></source>
972
+ </delivery>`);
973
+ const json = DomUtil.toJSON(xml, "SimpleJson");
974
+ expect(json.$source).toBe("<head></head>")
975
+ });
961
976
  });
977
+
978
+