fast-xml-parser 4.2.7 → 4.3.1
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,13 @@
|
|
|
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.3.1 / 2023-09-24**
|
|
4
|
+
* revert back "Fix typings for builder and parser to make return type generic" to avoid failure of existing projects. Need to decide a common approach.
|
|
5
|
+
|
|
6
|
+
**4.3.0 / 2023-09-20**
|
|
7
|
+
* Fix stopNodes to work with removeNSPrefix (#607) (#608) (By [Craig Andrews]https://github.com/candrews))
|
|
8
|
+
* Fix #610 ignore properties set to Object.prototype
|
|
9
|
+
* Fix typings for builder and parser to make return type generic (By [Sarah Dayan](https://github.com/sarahdayan))
|
|
10
|
+
|
|
3
11
|
**4.2.7 / 2023-07-30**
|
|
4
12
|
* Fix: builder should set text node correctly when only textnode is present (#589) (By [qianqing](https://github.com/joneqian))
|
|
5
13
|
* Fix: Fix for null and undefined attributes when building xml (#585) (#598). A null or undefined value should be ignored. (By [Eugenio Ceschia](https://github.com/cecia234))
|
package/package.json
CHANGED
|
@@ -79,6 +79,7 @@ Builder.prototype.j2x = function(jObj, level) {
|
|
|
79
79
|
let attrStr = '';
|
|
80
80
|
let val = '';
|
|
81
81
|
for (let key in jObj) {
|
|
82
|
+
if(!jObj.hasOwnProperty(key)) continue;
|
|
82
83
|
if (typeof jObj[key] === 'undefined') {
|
|
83
84
|
// supress undefined node only if it is not an attribute
|
|
84
85
|
if (this.isAttribute(key)) {
|
|
@@ -21,6 +21,8 @@ function arrToStr(arr, options, jPath, indentation) {
|
|
|
21
21
|
for (let i = 0; i < arr.length; i++) {
|
|
22
22
|
const tagObj = arr[i];
|
|
23
23
|
const tagName = propName(tagObj);
|
|
24
|
+
if(tagName === undefined) continue;
|
|
25
|
+
|
|
24
26
|
let newJPath = "";
|
|
25
27
|
if (jPath.length === 0) newJPath = tagName
|
|
26
28
|
else newJPath = `${jPath}.${tagName}`;
|
|
@@ -90,6 +92,7 @@ function propName(obj) {
|
|
|
90
92
|
const keys = Object.keys(obj);
|
|
91
93
|
for (let i = 0; i < keys.length; i++) {
|
|
92
94
|
const key = keys[i];
|
|
95
|
+
if(!obj.hasOwnProperty(key)) continue;
|
|
93
96
|
if (key !== ":@") return key;
|
|
94
97
|
}
|
|
95
98
|
}
|
|
@@ -98,6 +101,7 @@ function attr_to_str(attrMap, options) {
|
|
|
98
101
|
let attrStr = "";
|
|
99
102
|
if (attrMap && !options.ignoreAttributes) {
|
|
100
103
|
for (let attr in attrMap) {
|
|
104
|
+
if(!attrMap.hasOwnProperty(attr)) continue;
|
|
101
105
|
let attrVal = options.attributeValueProcessor(attr, attrMap[attr]);
|
|
102
106
|
attrVal = replaceEntitiesValue(attrVal, options);
|
|
103
107
|
if (attrVal === true && options.suppressBooleanAttributes) {
|
|
@@ -280,6 +280,7 @@ const parseXml = function(xmlData) {
|
|
|
280
280
|
}else {//Opening tag
|
|
281
281
|
let result = readTagExp(xmlData,i, this.options.removeNSPrefix);
|
|
282
282
|
let tagName= result.tagName;
|
|
283
|
+
const rawTagName = result.rawTagName;
|
|
283
284
|
let tagExp = result.tagExp;
|
|
284
285
|
let attrExpPresent = result.attrExpPresent;
|
|
285
286
|
let closeIndex = result.closeIndex;
|
|
@@ -305,7 +306,7 @@ const parseXml = function(xmlData) {
|
|
|
305
306
|
if(tagName !== xmlObj.tagname){
|
|
306
307
|
jPath += jPath ? "." + tagName : tagName;
|
|
307
308
|
}
|
|
308
|
-
if (this.isItStopNode(this.options.stopNodes, jPath, tagName)) {
|
|
309
|
+
if (this.isItStopNode(this.options.stopNodes, jPath, tagName)) {
|
|
309
310
|
let tagContent = "";
|
|
310
311
|
//self-closing tag
|
|
311
312
|
if(tagExp.length > 0 && tagExp.lastIndexOf("/") === tagExp.length - 1){
|
|
@@ -318,8 +319,8 @@ const parseXml = function(xmlData) {
|
|
|
318
319
|
//normal tag
|
|
319
320
|
else{
|
|
320
321
|
//read until closing tag is found
|
|
321
|
-
const result = this.readStopNodeData(xmlData,
|
|
322
|
-
if(!result) throw new Error(`Unexpected end of ${
|
|
322
|
+
const result = this.readStopNodeData(xmlData, rawTagName, closeIndex + 1);
|
|
323
|
+
if(!result) throw new Error(`Unexpected end of ${rawTagName}`);
|
|
323
324
|
i = result.i;
|
|
324
325
|
tagContent = result.tagContent;
|
|
325
326
|
}
|
|
@@ -504,6 +505,7 @@ function readTagExp(xmlData,i, removeNSPrefix, closingChar = ">"){
|
|
|
504
505
|
tagExp = tagExp.substr(separatorIndex + 1);
|
|
505
506
|
}
|
|
506
507
|
|
|
508
|
+
const rawTagName = tagName;
|
|
507
509
|
if(removeNSPrefix){
|
|
508
510
|
const colonIndex = tagName.indexOf(":");
|
|
509
511
|
if(colonIndex !== -1){
|
|
@@ -517,6 +519,7 @@ function readTagExp(xmlData,i, removeNSPrefix, closingChar = ">"){
|
|
|
517
519
|
tagExp: tagExp,
|
|
518
520
|
closeIndex: closeIndex,
|
|
519
521
|
attrExpPresent: attrExpPresent,
|
|
522
|
+
rawTagName: rawTagName,
|
|
520
523
|
}
|
|
521
524
|
}
|
|
522
525
|
/**
|