fast-xml-parser 5.5.5 → 5.5.6

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.5.5",
3
+ "version": "5.5.6",
4
4
  "description": "Validate XML, Parse XML, Build XML without C/C++ based libraries",
5
5
  "main": "./lib/fxp.cjs",
6
6
  "type": "module",
@@ -87,7 +87,7 @@
87
87
  }
88
88
  ],
89
89
  "dependencies": {
90
- "fast-xml-builder": "^1.1.3",
90
+ "fast-xml-builder": "^1.1.4",
91
91
  "path-expression-matcher": "^1.1.3",
92
92
  "strnum": "^2.1.2"
93
93
  }
package/src/fxp.d.ts CHANGED
@@ -516,6 +516,13 @@ export type XmlBuilderOptions = {
516
516
 
517
517
 
518
518
  oneListGroup?: boolean;
519
+
520
+ /**
521
+ * Maximum number of nested tags
522
+ *
523
+ * Defaults to `100`
524
+ */
525
+ maxNestedTags?: number;
519
526
  };
520
527
 
521
528
  type ESchema = string | object | Array<string | object>;
@@ -34,7 +34,8 @@ export default class DocTypeReader {
34
34
  `Entity count (${entityCount + 1}) exceeds maximum allowed (${this.options.maxEntityCount})`
35
35
  );
36
36
  }
37
- const escaped = entityName.replace(/[.\-+*:]/g, '\\.');
37
+ //const escaped = entityName.replace(/[.\-+*:]/g, '\\.');
38
+ const escaped = entityName.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
38
39
  entities[entityName] = {
39
40
  regx: RegExp(`&${escaped};`, "g"),
40
41
  val: val
@@ -621,7 +621,7 @@ function replaceEntitiesValue(val, tagName, jPath) {
621
621
  }
622
622
 
623
623
  // Replace DOCTYPE entities
624
- for (let entityName in this.docTypeEntities) {
624
+ for (const entityName of Object.keys(this.docTypeEntities)) {
625
625
  const entity = this.docTypeEntities[entityName];
626
626
  const matches = val.match(entity.regx);
627
627
 
@@ -653,19 +653,38 @@ function replaceEntitiesValue(val, tagName, jPath) {
653
653
  }
654
654
  }
655
655
  }
656
- if (val.indexOf('&') === -1) return val; // Early exit
657
-
658
656
  // Replace standard entities
659
- for (let entityName in this.lastEntities) {
657
+ for (const entityName of Object.keys(this.lastEntities)) {
660
658
  const entity = this.lastEntities[entityName];
659
+ const matches = val.match(entity.regex);
660
+ if (matches) {
661
+ this.entityExpansionCount += matches.length;
662
+ if (entityConfig.maxTotalExpansions &&
663
+ this.entityExpansionCount > entityConfig.maxTotalExpansions) {
664
+ throw new Error(
665
+ `Entity expansion limit exceeded: ${this.entityExpansionCount} > ${entityConfig.maxTotalExpansions}`
666
+ );
667
+ }
668
+ }
661
669
  val = val.replace(entity.regex, entity.val);
662
670
  }
663
- if (val.indexOf('&') === -1) return val; // Early exit
671
+ if (val.indexOf('&') === -1) return val;
664
672
 
665
673
  // Replace HTML entities if enabled
666
674
  if (this.options.htmlEntities) {
667
- for (let entityName in this.htmlEntities) {
675
+ for (const entityName of Object.keys(this.htmlEntities)) {
668
676
  const entity = this.htmlEntities[entityName];
677
+ const matches = val.match(entity.regex);
678
+ if (matches) {
679
+ //console.log(matches);
680
+ this.entityExpansionCount += matches.length;
681
+ if (entityConfig.maxTotalExpansions &&
682
+ this.entityExpansionCount > entityConfig.maxTotalExpansions) {
683
+ throw new Error(
684
+ `Entity expansion limit exceeded: ${this.entityExpansionCount} > ${entityConfig.maxTotalExpansions}`
685
+ );
686
+ }
687
+ }
669
688
  val = val.replace(entity.regex, entity.val);
670
689
  }
671
690
  }