fast-xml-parser 5.7.1 → 5.7.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fast-xml-parser",
3
- "version": "5.7.1",
3
+ "version": "5.7.2",
4
4
  "description": "Validate XML, Parse XML, Build XML without C/C++ based libraries",
5
5
  "main": "./lib/fxp.cjs",
6
6
  "type": "module",
@@ -69,7 +69,7 @@ function extractNamespace(rawTagName) {
69
69
  }
70
70
 
71
71
  export default class OrderedObjParser {
72
- constructor(options) {
72
+ constructor(options, externalEntities) {
73
73
  this.options = options;
74
74
  this.currentNode = null;
75
75
  this.tagsNodeStack = [];
@@ -92,7 +92,7 @@ export default class OrderedObjParser {
92
92
  if (typeof this.options.htmlEntities === "object") namedEntities = this.options.htmlEntities;
93
93
  else if (this.options.htmlEntities === true) namedEntities = { ...COMMON_HTML, ...CURRENCY };
94
94
  this.entityDecoder = new EntityDecoder({
95
- namedEntities: namedEntities,
95
+ namedEntities: { ...namedEntities, ...externalEntities },
96
96
  numericAllowed: this.options.htmlEntities,
97
97
  limit: {
98
98
  maxTotalExpansions: this.options.processEntities.maxTotalExpansions,
@@ -269,7 +269,7 @@ function buildAttributesMap(attrStr, jPath, tagName, force = false) {
269
269
 
270
270
  if (!hasAttrs) return;
271
271
 
272
- if (options.attributesGroupName) {
272
+ if (options.attributesGroupName && !options.preserveOrder) {
273
273
  const attrCollection = {};
274
274
  attrCollection[options.attributesGroupName] = attrs;
275
275
  return attrCollection;
@@ -655,12 +655,16 @@ function isItStopNode() {
655
655
  * @returns
656
656
  */
657
657
  function tagExpWithClosingIndex(xmlData, i, closingChar = ">") {
658
+ //TODO: ignore boolean attributes in tag expression
659
+ //TODO: if ignore attributes, dont read full attribute expression but the end. But read for xml declaration
658
660
  let attrBoundary = 0;
659
- const chars = [];
660
661
  const len = xmlData.length;
661
662
  const closeCode0 = closingChar.charCodeAt(0);
662
663
  const closeCode1 = closingChar.length > 1 ? closingChar.charCodeAt(1) : -1;
663
664
 
665
+ let result = '';
666
+ let segmentStart = i;
667
+
664
668
  for (let index = i; index < len; index++) {
665
669
  const code = xmlData.charCodeAt(index);
666
670
 
@@ -671,17 +675,18 @@ function tagExpWithClosingIndex(xmlData, i, closingChar = ">") {
671
675
  } else if (code === closeCode0) {
672
676
  if (closeCode1 !== -1) {
673
677
  if (xmlData.charCodeAt(index + 1) === closeCode1) {
674
- return { data: String.fromCharCode(...chars), index };
678
+ result += xmlData.substring(segmentStart, index);
679
+ return { data: result, index };
675
680
  }
676
681
  } else {
677
- return { data: String.fromCharCode(...chars), index };
682
+ result += xmlData.substring(segmentStart, index);
683
+ return { data: result, index };
678
684
  }
679
- } else if (code === 9) { // \t
680
- chars.push(32); // space
681
- continue;
685
+ } else if (code === 9 && !attrBoundary) { // \t - only replace with space outside attribute values
686
+ // Flush accumulated segment, add space, start new segment
687
+ result += xmlData.substring(segmentStart, index) + ' ';
688
+ segmentStart = index + 1;
682
689
  }
683
-
684
- chars.push(code);
685
690
  }
686
691
  }
687
692
 
@@ -31,8 +31,8 @@ export default class XMLParser {
31
31
  throw Error(`${result.err.msg}:${result.err.line}:${result.err.col}`)
32
32
  }
33
33
  }
34
- const orderedObjParser = new OrderedObjParser(this.options);
35
- orderedObjParser.entityDecoder.setExternalEntities(this.externalEntities);
34
+ const orderedObjParser = new OrderedObjParser(this.options, this.externalEntities);
35
+ // orderedObjParser.entityDecoder.setExternalEntities(this.externalEntities);
36
36
  const orderedResult = orderedObjParser.parseXml(xmlData);
37
37
  if (this.options.preserveOrder || orderedResult === undefined) return orderedResult;
38
38
  else return prettify(orderedResult, this.options, orderedObjParser.matcher, orderedObjParser.readonlyMatcher);