fast-xml-parser 5.4.0 → 5.4.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/CHANGELOG.md +9 -4
- package/lib/fxp.cjs +1 -1
- package/lib/fxp.d.cts +7 -0
- package/lib/fxp.min.js +1 -1
- package/lib/fxp.min.js.map +1 -1
- package/lib/fxparser.min.js +1 -1
- package/lib/fxparser.min.js.map +1 -1
- package/package.json +1 -1
- package/src/fxp.d.ts +7 -0
- package/src/xmlparser/DocTypeReader.js +10 -1
- package/src/xmlparser/OptionsBuilder.js +2 -0
- package/src/xmlparser/OrderedObjParser.js +16 -5
package/src/fxp.d.ts
CHANGED
|
@@ -34,6 +34,13 @@ export type ProcessEntitiesOptions = {
|
|
|
34
34
|
*/
|
|
35
35
|
maxExpandedLength?: number;
|
|
36
36
|
|
|
37
|
+
/**
|
|
38
|
+
* Maximum number of entities allowed in the XML
|
|
39
|
+
*
|
|
40
|
+
* Defaults to `100`
|
|
41
|
+
*/
|
|
42
|
+
maxEntityCount?: number;
|
|
43
|
+
|
|
37
44
|
/**
|
|
38
45
|
* Array of tag names where entity replacement is allowed.
|
|
39
46
|
* If null, entities are replaced in all tags.
|
|
@@ -7,8 +7,9 @@ export default class DocTypeReader {
|
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
readDocType(xmlData, i) {
|
|
10
|
-
|
|
11
10
|
const entities = Object.create(null);
|
|
11
|
+
let entityCount = 0;
|
|
12
|
+
|
|
12
13
|
if (xmlData[i + 3] === 'O' &&
|
|
13
14
|
xmlData[i + 4] === 'C' &&
|
|
14
15
|
xmlData[i + 5] === 'T' &&
|
|
@@ -26,11 +27,19 @@ export default class DocTypeReader {
|
|
|
26
27
|
let entityName, val;
|
|
27
28
|
[entityName, val, i] = this.readEntityExp(xmlData, i + 1, this.suppressValidationErr);
|
|
28
29
|
if (val.indexOf("&") === -1) { //Parameter entities are not supported
|
|
30
|
+
if (this.options.enabled !== false &&
|
|
31
|
+
this.options.maxEntityCount &&
|
|
32
|
+
entityCount >= this.options.maxEntityCount) {
|
|
33
|
+
throw new Error(
|
|
34
|
+
`Entity count (${entityCount + 1}) exceeds maximum allowed (${this.options.maxEntityCount})`
|
|
35
|
+
);
|
|
36
|
+
}
|
|
29
37
|
const escaped = entityName.replace(/[.\-+*:]/g, '\\.');
|
|
30
38
|
entities[entityName] = {
|
|
31
39
|
regx: RegExp(`&${escaped};`, "g"),
|
|
32
40
|
val: val
|
|
33
41
|
};
|
|
42
|
+
entityCount++;
|
|
34
43
|
}
|
|
35
44
|
}
|
|
36
45
|
else if (hasBody && hasSeq(xmlData, "!ELEMENT", i)) {
|
|
@@ -56,6 +56,7 @@ function normalizeProcessEntities(value) {
|
|
|
56
56
|
maxExpansionDepth: 10,
|
|
57
57
|
maxTotalExpansions: 1000,
|
|
58
58
|
maxExpandedLength: 100000,
|
|
59
|
+
maxEntityCount: 100,
|
|
59
60
|
allowedTags: null,
|
|
60
61
|
tagFilter: null
|
|
61
62
|
};
|
|
@@ -69,6 +70,7 @@ function normalizeProcessEntities(value) {
|
|
|
69
70
|
maxExpansionDepth: value.maxExpansionDepth ?? 10,
|
|
70
71
|
maxTotalExpansions: value.maxTotalExpansions ?? 1000,
|
|
71
72
|
maxExpandedLength: value.maxExpandedLength ?? 100000,
|
|
73
|
+
maxEntityCount: value.maxEntityCount ?? 100,
|
|
72
74
|
allowedTags: value.allowedTags ?? null,
|
|
73
75
|
tagFilter: value.tagFilter ?? null
|
|
74
76
|
};
|
|
@@ -414,6 +414,17 @@ const parseXml = function (xmlData) {
|
|
|
414
414
|
this.addChild(currentNode, childNode, jPath, startIndex);
|
|
415
415
|
jPath = jPath.substr(0, jPath.lastIndexOf("."));
|
|
416
416
|
}
|
|
417
|
+
else if(this.options.unpairedTags.indexOf(tagName) !== -1){//unpaired tag
|
|
418
|
+
const childNode = new xmlNode(tagName);
|
|
419
|
+
if(tagName !== tagExp && attrExpPresent){
|
|
420
|
+
childNode[":@"] = this.buildAttributesMap(tagExp, jPath);
|
|
421
|
+
}
|
|
422
|
+
this.addChild(currentNode, childNode, jPath, startIndex);
|
|
423
|
+
jPath = jPath.substr(0, jPath.lastIndexOf("."));
|
|
424
|
+
i = result.closeIndex;
|
|
425
|
+
// Continue to next iteration without changing currentNode
|
|
426
|
+
continue;
|
|
427
|
+
}
|
|
417
428
|
//opening tag
|
|
418
429
|
else {
|
|
419
430
|
const childNode = new xmlNode(tagName);
|
|
@@ -535,19 +546,19 @@ const replaceEntitiesValue = function (val, tagName, jPath) {
|
|
|
535
546
|
}
|
|
536
547
|
|
|
537
548
|
|
|
538
|
-
function saveTextToParentTag(textData,
|
|
549
|
+
function saveTextToParentTag(textData, parentNode, jPath, isLeafNode) {
|
|
539
550
|
if (textData) { //store previously collected data as textNode
|
|
540
|
-
if (isLeafNode === undefined) isLeafNode =
|
|
551
|
+
if (isLeafNode === undefined) isLeafNode = parentNode.child.length === 0
|
|
541
552
|
|
|
542
553
|
textData = this.parseTextData(textData,
|
|
543
|
-
|
|
554
|
+
parentNode.tagname,
|
|
544
555
|
jPath,
|
|
545
556
|
false,
|
|
546
|
-
|
|
557
|
+
parentNode[":@"] ? Object.keys(parentNode[":@"]).length !== 0 : false,
|
|
547
558
|
isLeafNode);
|
|
548
559
|
|
|
549
560
|
if (textData !== undefined && textData !== "")
|
|
550
|
-
|
|
561
|
+
parentNode.add(this.options.textNodeName, textData);
|
|
551
562
|
textData = "";
|
|
552
563
|
}
|
|
553
564
|
return textData;
|