fast-xml-parser 5.3.2 → 5.3.4

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.
@@ -41,8 +41,8 @@ export default class OrderedObjParser{
41
41
  "copyright" : { regex: /&(copy|#169);/g, val: "©" },
42
42
  "reg" : { regex: /&(reg|#174);/g, val: "®" },
43
43
  "inr" : { regex: /&(inr|#8377);/g, val: "₹" },
44
- "num_dec": { regex: /&#([0-9]{1,7});/g, val : (_, str) => String.fromCodePoint(Number.parseInt(str, 10)) },
45
- "num_hex": { regex: /&#x([0-9a-fA-F]{1,6});/g, val : (_, str) => String.fromCodePoint(Number.parseInt(str, 16)) },
44
+ "num_dec": { regex: /&#([0-9]{1,7});/g, val : (_, str) => fromCodePoint(str, 10, "&#") },
45
+ "num_hex": { regex: /&#x([0-9a-fA-F]{1,6});/g, val : (_, str) => fromCodePoint(str, 16, "&#x") },
46
46
  };
47
47
  this.addExternalEntities = addExternalEntities;
48
48
  this.parseXml = parseXml;
@@ -140,7 +140,7 @@ function resolveNameSpace(tagname) {
140
140
  //const attrsRegx = new RegExp("([\\w\\-\\.\\:]+)\\s*=\\s*(['\"])((.|\n)*?)\\2","gm");
141
141
  const attrsRegx = new RegExp('([^\\s=]+)\\s*(=\\s*([\'"])([\\s\\S]*?)\\3)?', 'gm');
142
142
 
143
- function buildAttributesMap(attrStr, jPath, tagName) {
143
+ function buildAttributesMap(attrStr, jPath) {
144
144
  if (this.options.ignoreAttributes !== true && typeof attrStr === 'string') {
145
145
  // attrStr = attrStr.replace(/\r?\n/g, ' ');
146
146
  //attrStr = attrStr || attrStr.trim();
@@ -252,14 +252,14 @@ const parseXml = function(xmlData) {
252
252
 
253
253
  textData = this.saveTextToParentTag(textData, currentNode, jPath);
254
254
  if( (this.options.ignoreDeclaration && tagData.tagName === "?xml") || this.options.ignorePiTags){
255
-
255
+ //do nothing
256
256
  }else{
257
257
 
258
258
  const childNode = new xmlNode(tagData.tagName);
259
259
  childNode.add(this.options.textNodeName, "");
260
260
 
261
261
  if(tagData.tagName !== tagData.tagExp && tagData.attrExpPresent){
262
- childNode[":@"] = this.buildAttributesMap(tagData.tagExp, jPath, tagData.tagName);
262
+ childNode[":@"] = this.buildAttributesMap(tagData.tagExp, jPath);
263
263
  }
264
264
  this.addChild(currentNode, childNode, jPath, i);
265
265
  }
@@ -306,7 +306,12 @@ const parseXml = function(xmlData) {
306
306
  let closeIndex = result.closeIndex;
307
307
 
308
308
  if (this.options.transformTagName) {
309
- tagName = this.options.transformTagName(tagName);
309
+ //console.log(tagExp, tagName)
310
+ const newTagName = this.options.transformTagName(tagName);
311
+ if(tagExp === tagName) {
312
+ tagExp = newTagName
313
+ }
314
+ tagName = newTagName;
310
315
  }
311
316
 
312
317
  //save text as child node
@@ -357,7 +362,8 @@ const parseXml = function(xmlData) {
357
362
  const childNode = new xmlNode(tagName);
358
363
 
359
364
  if(tagName !== tagExp && attrExpPresent){
360
- childNode[":@"] = this.buildAttributesMap(tagExp, jPath, tagName);
365
+ childNode[":@"] = this.buildAttributesMap(tagExp, jPath
366
+ );
361
367
  }
362
368
  if(tagContent) {
363
369
  tagContent = this.parseTextData(tagContent, tagName, jPath, true, attrExpPresent, true, true);
@@ -379,12 +385,16 @@ const parseXml = function(xmlData) {
379
385
  }
380
386
 
381
387
  if(this.options.transformTagName) {
382
- tagName = this.options.transformTagName(tagName);
388
+ const newTagName = this.options.transformTagName(tagName);
389
+ if(tagExp === tagName) {
390
+ tagExp = newTagName
391
+ }
392
+ tagName = newTagName;
383
393
  }
384
394
 
385
395
  const childNode = new xmlNode(tagName);
386
396
  if(tagName !== tagExp && attrExpPresent){
387
- childNode[":@"] = this.buildAttributesMap(tagExp, jPath, tagName);
397
+ childNode[":@"] = this.buildAttributesMap(tagExp, jPath);
388
398
  }
389
399
  this.addChild(currentNode, childNode, jPath, startIndex);
390
400
  jPath = jPath.substr(0, jPath.lastIndexOf("."));
@@ -395,7 +405,7 @@ const parseXml = function(xmlData) {
395
405
  this.tagsNodeStack.push(currentNode);
396
406
 
397
407
  if(tagName !== tagExp && attrExpPresent){
398
- childNode[":@"] = this.buildAttributesMap(tagExp, jPath, tagName);
408
+ childNode[":@"] = this.buildAttributesMap(tagExp, jPath);
399
409
  }
400
410
  this.addChild(currentNode, childNode, jPath, startIndex);
401
411
  currentNode = childNode;
@@ -416,6 +426,7 @@ function addChild(currentNode, childNode, jPath, startIndex){
416
426
  if (!this.options.captureMetaData) startIndex = undefined;
417
427
  const result = this.options.updateTag(childNode.tagname, jPath, childNode[":@"])
418
428
  if(result === false){
429
+ //do nothing
419
430
  } else if(typeof result === "string"){
420
431
  childNode.tagname = result
421
432
  currentNode.addChild(childNode, startIndex);
@@ -616,3 +627,13 @@ function parseValue(val, shouldParse, options) {
616
627
  }
617
628
  }
618
629
  }
630
+
631
+ function fromCodePoint(str, base, prefix){
632
+ const codePoint = Number.parseInt(str, base);
633
+
634
+ if (codePoint >= 0 && codePoint <= 0x10FFFF) {
635
+ return String.fromCodePoint(codePoint);
636
+ } else {
637
+ return prefix +str + ";";
638
+ }
639
+ }