fast-xml-parser 4.2.0 → 4.2.1

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 CHANGED
@@ -1,5 +1,8 @@
1
1
  Note: If you find missing information about particular minor version, that version must have been changed without any functional change in this library.
2
2
 
3
+ **4.2.1 / 2023-04-18**
4
+ * fix: jpath after unpaired tags
5
+
3
6
  **4.2.0 / 2023-04-09**
4
7
  * support `updateTag` parser property
5
8
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fast-xml-parser",
3
- "version": "4.2.0",
3
+ "version": "4.2.1",
4
4
  "description": "Validate XML, Parse XML, Build XML without C/C++ based libraries",
5
5
  "main": "./src/fxp.js",
6
6
  "scripts": {
@@ -206,8 +206,17 @@ const parseXml = function(xmlData) {
206
206
  textData = this.saveTextToParentTag(textData, currentNode, jPath);
207
207
  }
208
208
 
209
- jPath = jPath.substr(0, jPath.lastIndexOf("."));
210
-
209
+ //check if last tag of nested tag was unpaired tag
210
+ const lastTagName = jPath.substring(jPath.lastIndexOf(".")+1);
211
+ let propIndex = 0
212
+ if(lastTagName && this.options.unpairedTags.indexOf(lastTagName) !== -1 ){
213
+ propIndex = jPath.lastIndexOf('.', jPath.lastIndexOf('.')-1)
214
+ if(propIndex < 1) propIndex = jPath.lastIndexOf(".");
215
+ }else{
216
+ propIndex = jPath.lastIndexOf(".");
217
+ }
218
+ jPath = jPath.substring(0, propIndex);
219
+
211
220
  currentNode = this.tagsNodeStack.pop();//avoid recursion, set the parent tag scope
212
221
  textData = "";
213
222
  i = closeIndex;
@@ -284,23 +293,22 @@ const parseXml = function(xmlData) {
284
293
  }
285
294
  }
286
295
 
287
- if(tagName !== xmlObj.tagname){
288
- jPath += jPath ? "." + tagName : tagName;
289
- }
290
-
291
296
  //check if last tag was unpaired tag
292
297
  const lastTag = currentNode;
293
298
  if(lastTag && this.options.unpairedTags.indexOf(lastTag.tagname) !== -1 ){
294
299
  currentNode = this.tagsNodeStack.pop();
300
+ jPath = jPath.substring(0, jPath.lastIndexOf("."));
301
+ }
302
+ if(tagName !== xmlObj.tagname){
303
+ jPath += jPath ? "." + tagName : tagName;
295
304
  }
296
-
297
305
  if (this.isItStopNode(this.options.stopNodes, jPath, tagName)) { //TODO: namespace
298
306
  let tagContent = "";
299
307
  //self-closing tag
300
308
  if(tagExp.length > 0 && tagExp.lastIndexOf("/") === tagExp.length - 1){
301
309
  i = result.closeIndex;
302
310
  }
303
- //boolean tag
311
+ //unpaired tag
304
312
  else if(this.options.unpairedTags.indexOf(tagName) !== -1){
305
313
  i = result.closeIndex;
306
314
  }
@@ -343,8 +351,8 @@ const parseXml = function(xmlData) {
343
351
  if(tagName !== tagExp && attrExpPresent){
344
352
  childNode[":@"] = this.buildAttributesMap(tagExp, jPath, tagName);
345
353
  }
346
- jPath = jPath.substr(0, jPath.lastIndexOf("."));
347
354
  this.addChild(currentNode, childNode, jPath)
355
+ jPath = jPath.substr(0, jPath.lastIndexOf("."));
348
356
  }
349
357
  //opening tag
350
358
  else{