Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fast-xml-parser

Package Overview
Dependencies
Maintainers
1
Versions
136
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fast-xml-parser - npm Package Compare versions

Comparing version 2.3.1 to 2.4.1

0

bin/InvalidXmlException.js

@@ -0,0 +0,0 @@ var InvalidXmlException = function (msg){

12

bin/parser.js

@@ -14,3 +14,4 @@ var getAllMatches = require("./util").getAllMatches;

//var tagsRegx = new RegExp("<(\\/?[a-zA-Z0-9_:]+)([^>\\/]*)(\\/?)>([^<]+)?","g");
var tagsRegx = new RegExp("<(\\/?[\\w:-]+)([^>]*)>([^<]+)?","g");
//var tagsRegx = new RegExp("<(\\/?[\\w:-]+)([^>]*)>([^<]+)?","g");
var tagsRegx = new RegExp("<(\\/?[\\w:-]+)([^>]*)>(<!\\[CDATA\\[(.*)\\]\\]>)?([^<]+)?","g");

@@ -39,3 +40,3 @@ var defaultOptions = {

options = buildOptions(options);
xmlData = xmlData.replace(/>(\s+)/g, ">");//Remove spaces and make it single line.
//xmlData = xmlData.replace(/>(\s+)/g, ">");//Remove spaces and make it single line.
var tags = getAllMatches(xmlData,tagsRegx);

@@ -48,3 +49,4 @@ var xmlObj = new xmlNode('!xml');

nexttag = i+1 < tags.length ? resolveNameSpace(tags[i+1][1],options.ignoreNameSpace) : undefined,
attrsStr = tags[i][2], val = tags[i][3], attrs;
attrsStr = tags[i][2], attrs,
val = tags[i][4] === undefined ? tags[i][5] : simplifyCDATA(tags[i][4]);

@@ -92,4 +94,6 @@ if(tag.indexOf("/") === 0){//ending tag

function simplifyCDATA(cdata){
return cdata.replace(new RegExp("\\]\\]><\!\\[CDATA\\[", 'g'), "");
}
function resolveNameSpace(tagname,ignore){

@@ -96,0 +100,0 @@ if(ignore){

@@ -0,0 +0,0 @@ var getAllMatches = function(string, regex) {

@@ -13,5 +13,12 @@ var getAllMatches = require("./util").getAllMatches;

throw new InvalidXmlException("Invalid tag at "+ lineNum + ":" + i);
}else if(xmlData[i+1] === "!"){//comment tag
var comment = getCommentTag(xmlData,i,lineNum);
i+=comment.length-1;
}else if(xmlData[i+1] === "!"){//comment tag or CDATA tag
var tg = "";
if(xmlData[i+2] === "-")
tg = getCommentTag(xmlData,i,lineNum);
else if(xmlData[i+2] === "["){
tg = getCDATA(xmlData,i,lineNum);
}else{
throw new InvalidXmlException("Invalid tag at "+ lineNum + ":" + i);
}
i+=tg.length-1;
}else if(xmlData[i+1] === "/"){//closing tag

@@ -59,2 +66,18 @@ i+=2;

/**
* Validate and return comment tag
*/
function getCDATA(xmlData,startIndex,lineNum){
for (var i = startIndex; i < xmlData.length; i++){
if(xmlData[i] === "<" && xmlData[i+1] === "/") {
i--;
break;
}
}
if(xmlData.substr(startIndex,9) === "<![CDATA[" && xmlData.substr(i-2,3) === "]]>")
return xmlData.substring(startIndex,i);
else
throw new InvalidXmlException("Invalid CDATA tag at " + lineNum +":"+ startIndex);
}
/**
* Validate and return end ending tag

@@ -61,0 +84,0 @@ */

@@ -0,0 +0,0 @@ #!/usr/bin/env node

@@ -25,3 +25,4 @@ (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.parser = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){

//var tagsRegx = new RegExp("<(\\/?[a-zA-Z0-9_:]+)([^>\\/]*)(\\/?)>([^<]+)?","g");
var tagsRegx = new RegExp("<(\\/?[\\w:-]+)([^>]*)>([^<]+)?","g");
//var tagsRegx = new RegExp("<(\\/?[\\w:-]+)([^>]*)>([^<]+)?","g");
var tagsRegx = new RegExp("<(\\/?[\\w:-]+)([^>]*)>(<!\\[CDATA\\[(.*)\\]\\]>)?([^<]+)?","g");

@@ -50,3 +51,3 @@ var defaultOptions = {

options = buildOptions(options);
xmlData = xmlData.replace(/>(\s+)/g, ">");//Remove spaces and make it single line.
//xmlData = xmlData.replace(/>(\s+)/g, ">");//Remove spaces and make it single line.
var tags = getAllMatches(xmlData,tagsRegx);

@@ -59,3 +60,4 @@ var xmlObj = new xmlNode('!xml');

nexttag = i+1 < tags.length ? resolveNameSpace(tags[i+1][1],options.ignoreNameSpace) : undefined,
attrsStr = tags[i][2], val = tags[i][3], attrs;
attrsStr = tags[i][2], attrs,
val = tags[i][4] === undefined ? tags[i][5] : simplifyCDATA(tags[i][4]);

@@ -103,4 +105,6 @@ if(tag.indexOf("/") === 0){//ending tag

function simplifyCDATA(cdata){
return cdata.replace(new RegExp("\\]\\]><\!\\[CDATA\\[", 'g'), "");
}
function resolveNameSpace(tagname,ignore){

@@ -206,5 +210,12 @@ if(ignore){

throw new InvalidXmlException("Invalid tag at "+ lineNum + ":" + i);
}else if(xmlData[i+1] === "!"){//comment tag
var comment = getCommentTag(xmlData,i,lineNum);
i+=comment.length-1;
}else if(xmlData[i+1] === "!"){//comment tag or CDATA tag
var tg = "";
if(xmlData[i+2] === "-")
tg = getCommentTag(xmlData,i,lineNum);
else if(xmlData[i+2] === "["){
tg = getCDATA(xmlData,i,lineNum);
}else{
throw new InvalidXmlException("Invalid tag at "+ lineNum + ":" + i);
}
i+=tg.length-1;
}else if(xmlData[i+1] === "/"){//closing tag

@@ -252,2 +263,18 @@ i+=2;

/**
* Validate and return comment tag
*/
function getCDATA(xmlData,startIndex,lineNum){
for (var i = startIndex; i < xmlData.length; i++){
if(xmlData[i] === "<" && xmlData[i+1] === "/") {
i--;
break;
}
}
if(xmlData.substr(startIndex,9) === "<![CDATA[" && xmlData.substr(i-2,3) === "]]>")
return xmlData.substring(startIndex,i);
else
throw new InvalidXmlException("Invalid CDATA tag at " + lineNum +":"+ startIndex);
}
/**
* Validate and return end ending tag

@@ -254,0 +281,0 @@ */

{
"name": "fast-xml-parser",
"version": "2.3.1",
"version": "2.4.1",
"description": "Validate XML or Parse XML to JS/JSON very fast without C/C++ based libraries",

@@ -5,0 +5,0 @@ "main": "./bin/parser.js",

@@ -0,0 +0,0 @@ # [fast-xml-parser](https://www.npmjs.com/package/fast-xml-parser)

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc