fast-xml-parser 5.3.5 → 5.3.7

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.
@@ -1,46 +1,86 @@
1
-
2
1
  export const defaultOptions = {
3
- preserveOrder: false,
4
- attributeNamePrefix: '@_',
5
- attributesGroupName: false,
6
- textNodeName: '#text',
7
- ignoreAttributes: true,
8
- removeNSPrefix: false, // remove NS from tag name or attribute name if true
9
- allowBooleanAttributes: false, //a tag can have attributes without any value
10
- //ignoreRootElement : false,
11
- parseTagValue: true,
12
- parseAttributeValue: false,
13
- trimValues: true, //Trim string values of tag and attributes
14
- cdataPropName: false,
15
- numberParseOptions: {
16
- hex: true,
17
- leadingZeros: true,
18
- eNotation: true
19
- },
20
- tagValueProcessor: function(tagName, val) {
21
- return val;
22
- },
23
- attributeValueProcessor: function(attrName, val) {
24
- return val;
25
- },
26
- stopNodes: [], //nested tags will not be parsed even for errors
27
- alwaysCreateTextNode: false,
28
- isArray: () => false,
29
- commentPropName: false,
30
- unpairedTags: [],
31
- processEntities: true,
32
- htmlEntities: false,
33
- ignoreDeclaration: false,
34
- ignorePiTags: false,
35
- transformTagName: false,
36
- transformAttributeName: false,
37
- updateTag: function(tagName, jPath, attrs){
38
- return tagName
39
- },
40
- // skipEmptyListItem: false
41
- captureMetaData: false,
42
- };
43
-
44
- export const buildOptions = function(options) {
45
- return Object.assign({}, defaultOptions, options);
2
+ preserveOrder: false,
3
+ attributeNamePrefix: '@_',
4
+ attributesGroupName: false,
5
+ textNodeName: '#text',
6
+ ignoreAttributes: true,
7
+ removeNSPrefix: false, // remove NS from tag name or attribute name if true
8
+ allowBooleanAttributes: false, //a tag can have attributes without any value
9
+ //ignoreRootElement : false,
10
+ parseTagValue: true,
11
+ parseAttributeValue: false,
12
+ trimValues: true, //Trim string values of tag and attributes
13
+ cdataPropName: false,
14
+ numberParseOptions: {
15
+ hex: true,
16
+ leadingZeros: true,
17
+ eNotation: true
18
+ },
19
+ tagValueProcessor: function (tagName, val) {
20
+ return val;
21
+ },
22
+ attributeValueProcessor: function (attrName, val) {
23
+ return val;
24
+ },
25
+ stopNodes: [], //nested tags will not be parsed even for errors
26
+ alwaysCreateTextNode: false,
27
+ isArray: () => false,
28
+ commentPropName: false,
29
+ unpairedTags: [],
30
+ processEntities: true,
31
+ htmlEntities: false,
32
+ ignoreDeclaration: false,
33
+ ignorePiTags: false,
34
+ transformTagName: false,
35
+ transformAttributeName: false,
36
+ updateTag: function (tagName, jPath, attrs) {
37
+ return tagName
38
+ },
39
+ // skipEmptyListItem: false
40
+ captureMetaData: false,
46
41
  };
42
+
43
+ /**
44
+ * Normalizes processEntities option for backward compatibility
45
+ * @param {boolean|object} value
46
+ * @returns {object} Always returns normalized object
47
+ */
48
+ function normalizeProcessEntities(value) {
49
+ // Boolean backward compatibility
50
+ if (typeof value === 'boolean') {
51
+ return {
52
+ enabled: value, // true or false
53
+ maxEntitySize: 10000,
54
+ maxExpansionDepth: 10,
55
+ maxTotalExpansions: 1000,
56
+ maxExpandedLength: 100000,
57
+ allowedTags: null,
58
+ tagFilter: null
59
+ };
60
+ }
61
+
62
+ // Object config - merge with defaults
63
+ if (typeof value === 'object' && value !== null) {
64
+ return {
65
+ enabled: value.enabled !== false, // default true if not specified
66
+ maxEntitySize: value.maxEntitySize ?? 10000,
67
+ maxExpansionDepth: value.maxExpansionDepth ?? 10,
68
+ maxTotalExpansions: value.maxTotalExpansions ?? 1000,
69
+ maxExpandedLength: value.maxExpandedLength ?? 100000,
70
+ allowedTags: value.allowedTags ?? null,
71
+ tagFilter: value.tagFilter ?? null
72
+ };
73
+ }
74
+
75
+ // Default to enabled with limits
76
+ return normalizeProcessEntities(true);
77
+ }
78
+
79
+ export const buildOptions = function (options) {
80
+ const built = Object.assign({}, defaultOptions, options);
81
+
82
+ // Always normalize processEntities for backward compatibility and validation
83
+ built.processEntities = normalizeProcessEntities(built.processEntities);
84
+ //console.debug(built.processEntities)
85
+ return built;
86
+ };