Socket
Socket
Sign inDemoInstall

xml2json

Package Overview
Dependencies
Maintainers
2
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

xml2json - npm Package Compare versions

Comparing version 0.9.0 to 0.9.1

test/fixtures/xmlsanitize2.json

8

lib/sanitize.js

@@ -30,3 +30,3 @@ /**

exports.sanitize = function sanitize(value) {
exports.sanitize = function sanitize(value, reverse) {
if (typeof value !== 'string') {

@@ -37,3 +37,7 @@ return value;

Object.keys(chars).forEach(function(key) {
value = value.replace(new RegExp(escapeRegExp(key), 'g'), chars[key]);
if (reverse) {
value = value.replace(new RegExp(escapeRegExp(chars[key]), 'g'), key);
} else {
value = value.replace(new RegExp(escapeRegExp(key), 'g'), chars[key]);
}
});

@@ -40,0 +44,0 @@

@@ -64,3 +64,3 @@ var expat = require('node-expat');

if (options.sanitize) {
currentObject['$t'] = sanitizer.sanitize(currentObject['$t']);
currentObject['$t'] = sanitizer.sanitize(currentObject['$t'], true);
}

@@ -67,0 +67,0 @@

{
"name": "xml2json",
"version": "0.9.0",
"version": "0.9.1",
"description": "Converts xml to json and vice-versa, using node-expat.",

@@ -5,0 +5,0 @@ "repository": "git://github.com/buglabs/node-xml2json.git",

@@ -14,3 +14,3 @@ # Simple XML2JSON Parser

This module uses node-expat which will require extra steps if you want to get it installed on Windows. Please
refer to its [documentation](http://node-xmpp.org/doc/expat.html#installing-on-windows?).
refer to its [documentation](http://node-xmpp.org/doc/expat.html#installing-on-windows?). Also, please be aware of known issues installing node-expat on Windows: https://github.com/node-xmpp/node-expat/issues?utf8=✓&q=is%3Aissue+is%3Aopen+windows

@@ -26,5 +26,16 @@ ## Installation

// xml to json
var xml = "<foo>bar</foo>";
var json = parser.toJson(xml); //returns a string containing the JSON structure by default
console.log(json);
// json to xml
var json = {
root: {
name: {'$t': 'John', id:'idx'} // $t for text, and all others will be attributes
}
};
var xml = parser.toXml(json); //returns xml <root><name for="idx">John</name></root>
console.log(xml)
```

@@ -31,0 +42,0 @@ ## API

@@ -91,3 +91,3 @@ var fs = require('fs');

var xml = internals.readFixture('xmlsanitize.xml');
var result = parser.toJson(xml, {});
var result = parser.toJson(xml, {sanitize: true});
var json = internals.readFixture('xmlsanitize.json');

@@ -100,2 +100,13 @@

it('does xmlsanitize of text', function (done) {
var xml = internals.readFixture('xmlsanitize2.xml');
var result = parser.toJson(xml, {sanitize: true});
var json = internals.readFixture('xmlsanitize2.json');
expect(result).to.deep.equal(json);
done();
});
it('throws error on bad options', function (done) {

@@ -102,0 +113,0 @@

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