fast-xml-parser 4.0.5 → 4.0.8

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  Note: If you find missing information about particular minor version, that version must have been changed without any functional change in this library.
2
2
 
3
+ **4.0.8 / 2022-03-18**
4
+ * Fix CDATA parsing returning empty string when value = 0 (#451) (By [ndelanou](https://github.com/ndelanou))
5
+ * Fix stopNodes when same tag appears inside node (#456) (By [patrickshipe](https://github.com/patrickshipe))
6
+ * fix #468: prettify own properties only
7
+
8
+ **4.0.7 / 2022-03-18**
9
+ * support CDATA even if tag order is not preserved
10
+ * support Comments even if tag order is not preserved
11
+ * fix #446: XMLbuilder should not indent XML declaration
12
+
13
+ **4.0.6 / 2022-03-08**
14
+ * fix: call tagValueProcessor only once for array items
15
+ * fix: missing changed for #437
16
+
3
17
  **4.0.5 / 2022-03-06**
4
18
  * fix #437: call tagValueProcessor from XML builder
5
19
 
package/README.md CHANGED
@@ -11,6 +11,8 @@
11
11
 
12
12
  Validate XML, Parse XML to JS Object, or Build XML from JS Object without C/C++ based libraries and no callback.
13
13
 
14
+ > Looking for maintainers
15
+
14
16
  <a href="https://opencollective.com/fast-xml-parser/donate" target="_blank">
15
17
  <img src="https://opencollective.com/fast-xml-parser/donate/button@2x.png?color=blue" width=200 />
16
18
  </a>
@@ -18,6 +20,9 @@ Validate XML, Parse XML to JS Object, or Build XML from JS Object without C/C++
18
20
 
19
21
  Check [ThankYouBackers](https://github.com/NaturalIntelligence/ThankYouBackers) for our contributors
20
22
 
23
+
24
+
25
+ [![](static/img/ni_ads_ads.gif)](https://github.com/NaturalIntelligence/ads/)
21
26
  ## Users
22
27
 
23
28
  <a href="https://github.com/renovatebot/renovate" title="renovate" ><img src="https://avatars1.githubusercontent.com/u/38656520" width="60px" ></a>
@@ -99,12 +104,12 @@ In a HTML page
99
104
 
100
105
  Check lib folder for different browser bundles
101
106
 
102
- | Bundle Name | Size |
103
- | -- | -- |
104
- | fxbuilder.min.js | 5.2K |
105
- | fxparser.js | 50K |
106
- | fxparser.min.js | 17K |
107
- | fxp.min.js | 22K |
107
+ | Bundle Name | Size |
108
+ | ------------------ | ---- |
109
+ | fxbuilder.min.js | 5.2K |
110
+ | fxparser.js | 50K |
111
+ | fxparser.min.js | 17K |
112
+ | fxp.min.js | 22K |
108
113
  | fxvalidator.min.js | 5.7K |
109
114
 
110
115
  ### Documents
@@ -139,7 +144,7 @@ Check lib folder for different browser bundles
139
144
  * **[BigBit standard](https://github.com/amitguptagwl/bigbit)** :
140
145
  * Single text encoding to replace UTF-8, UTF-16, UTF-32 and more with less memory.
141
146
  * Single Numeric datatype alternative of integer, float, double, long, decimal and more without precision loss.
142
- * **[Cytorus](https://github.com/NaturalIntelligence/cytorus)**: Now be specific and flexible while running E2E tests.
147
+ * **[Cytorus](https://github.com/NaturalIntelligence/cytorus)**: Be specific and flexible while running E2E tests.
143
148
  * Run tests only for a particular User Story
144
149
  * Run tests for a route or from a route
145
150
  * Customizable reporting
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fast-xml-parser",
3
- "version": "4.0.5",
3
+ "version": "4.0.8",
4
4
  "description": "Validate XML, Parse XML, Build XML without C/C++ based libraries",
5
5
  "main": "./src/fxp.js",
6
6
  "scripts": {
@@ -156,7 +156,7 @@ function buildAttrPairStr(attrName, val){
156
156
  function processTextOrObjNode (object, key, level) {
157
157
  const result = this.j2x(object, level + 1);
158
158
  if (object[this.options.textNodeName] !== undefined && Object.keys(object).length === 1) {
159
- return this.buildTextNode(result.val, key, result.attrStr, level);
159
+ return this.buildTextNode(object[this.options.textNodeName], key, result.attrStr, level);
160
160
  } else {
161
161
  return this.buildObjNode(result.val, key, result.attrStr, level);
162
162
  }
@@ -172,11 +172,10 @@ function buildObjectNode(val, key, attrStr, level) {
172
172
  }
173
173
 
174
174
  if (attrStr && val.indexOf('<') === -1) {
175
- return (
176
- this.indentate(level) + '<' + key + attrStr + piClosingChar + '>' +
177
- val +
178
- tagEndExp );
179
- } else {
175
+ return ( this.indentate(level) + '<' + key + attrStr + piClosingChar + '>' + val + tagEndExp );
176
+ } else if (this.options.commentPropName !== false && key === this.options.commentPropName && piClosingChar.length === 0) {
177
+ return this.indentate(level) + `<!--${val}-->` + this.newLine;
178
+ }else {
180
179
  return (
181
180
  this.indentate(level) + '<' + key + attrStr + piClosingChar + this.tagEndChar +
182
181
  val +
@@ -194,20 +193,27 @@ function buildEmptyObjNode(val, key, attrStr, level) {
194
193
  }
195
194
 
196
195
  function buildTextValNode(val, key, attrStr, level) {
197
- let textValue = this.options.tagValueProcessor(key, val);
198
- textValue = this.replaceEntitiesValue(val);
199
-
200
- if( textValue === '' && this.options.unpairedTags.indexOf(key) !== -1){ //unpaired
201
- if(this.options.suppressUnpairedNode){
202
- return this.indentate(level) + '<' + key + this.tagEndChar;
203
- }else{
204
- return this.indentate(level) + '<' + key + "/" + this.tagEndChar;
205
- }
196
+ if (this.options.cdataPropName !== false && key === this.options.cdataPropName) {
197
+ return this.indentate(level) + `<![CDATA[${val}]]>` + this.newLine;
198
+ }else if (this.options.commentPropName !== false && key === this.options.commentPropName) {
199
+ return this.indentate(level) + `<!--${val}-->` + this.newLine;
206
200
  }else{
207
- return (
208
- this.indentate(level) + '<' + key + attrStr + '>' +
209
- textValue +
210
- '</' + key + this.tagEndChar );
201
+ let textValue = this.options.tagValueProcessor(key, val);
202
+ textValue = this.replaceEntitiesValue(textValue);
203
+
204
+ if( textValue === '' && this.options.unpairedTags.indexOf(key) !== -1){ //unpaired
205
+ if(this.options.suppressUnpairedNode){
206
+ return this.indentate(level) + '<' + key + this.tagEndChar;
207
+ }else{
208
+ return this.indentate(level) + '<' + key + "/" + this.tagEndChar;
209
+ }
210
+ } else{
211
+ return (
212
+ this.indentate(level) + '<' + key + attrStr + '>' +
213
+ textValue +
214
+ '</' + key + this.tagEndChar );
215
+ }
216
+
211
217
  }
212
218
  }
213
219
 
@@ -41,7 +41,10 @@ function arrToStr(arr, options, jPath, level){
41
41
  continue;
42
42
  }else if( tagName[0] === "?"){
43
43
  const attStr = attr_to_str(tagObj[":@"], options);
44
- xmlStr += indentation + `<${tagName} ${tagObj[tagName][0][options.textNodeName]} ${attStr}?>`;
44
+ const tempInd = tagName === "?xml" ? "" : indentation;
45
+ let piTextNodeName = tagObj[tagName][0][options.textNodeName];
46
+ piTextNodeName = piTextNodeName.length !== 0 ? " " + piTextNodeName : ""; //remove extra spacing
47
+ xmlStr += tempInd + `<${tagName}${piTextNodeName}${attStr}?>`;
45
48
  continue;
46
49
  }
47
50
  const attStr = attr_to_str(tagObj[":@"], options);
@@ -251,7 +251,7 @@ const parseXml = function(xmlData) {
251
251
  currentNode.add(this.options.cdataPropName, [ { [this.options.textNodeName] : tagExp } ]);
252
252
  }else{
253
253
  let val = this.parseTextData(tagExp, currentNode.tagname, jPath, true, false, true);
254
- if(!val) val = "";
254
+ if(val == undefined) val = "";
255
255
  currentNode.add(this.options.textNodeName, val);
256
256
  }
257
257
 
@@ -486,17 +486,35 @@ function readTagExp(xmlData,i, removeNSPrefix, closingChar = ">"){
486
486
  */
487
487
  function readStopNodeData(xmlData, tagName, i){
488
488
  const startIndex = i;
489
+ // Starting at 1 since we already have an open tag
490
+ let openTagCount = 1;
491
+
489
492
  for (; i < xmlData.length; i++) {
490
- if( xmlData[i] === "<" && xmlData[i+1] === "/"){
491
- const closeIndex = findClosingIndex(xmlData, ">", i, `${tagName} is not closed`);
492
- let closeTagName = xmlData.substring(i+2,closeIndex).trim();
493
- if(closeTagName === tagName){
494
- return {
495
- tagContent: xmlData.substring(startIndex, i),
496
- i : closeIndex
493
+ if( xmlData[i] === "<"){
494
+ if (xmlData[i+1] === "/") {
495
+ const closeIndex = findClosingIndex(xmlData, ">", i, `${tagName} is not closed`);
496
+ let closeTagName = xmlData.substring(i+2,closeIndex).trim();
497
+ if(closeTagName === tagName){
498
+ openTagCount--;
499
+ if (openTagCount === 0) {
500
+ return {
501
+ tagContent: xmlData.substring(startIndex, i),
502
+ i : closeIndex
503
+ }
504
+ }
505
+ }
506
+ i=closeIndex;
507
+ } else {
508
+ const tagData = readTagExp(xmlData, i, '>')
509
+
510
+ if (tagData) {
511
+ const openTagName = tagData && tagData.tagName;
512
+ if (openTagName === tagName) {
513
+ openTagCount++;
514
+ }
515
+ i=tagData.closeIndex;
497
516
  }
498
517
  }
499
- i=closeIndex;
500
518
  }
501
519
  }//end for loop
502
520
  }
@@ -46,9 +46,9 @@ function compress(arr, options, jPath){
46
46
  else val = "";
47
47
  }
48
48
 
49
- if(compressedObj[property] !== undefined) {
49
+ if(compressedObj[property] !== undefined && compressedObj.hasOwnProperty(property)) {
50
50
  if(!Array.isArray(compressedObj[property])) {
51
- compressedObj[property] = [ compressedObj[property] ];
51
+ compressedObj[property] = [ compressedObj[property] ];
52
52
  }
53
53
  compressedObj[property].push(val);
54
54
  }else{