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

xml-js-v2

Package Overview
Dependencies
Maintainers
0
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

xml-js-v2 - npm Package Compare versions

Comparing version 2.0.0 to 2.1.0

11

lib/js2xml.js

@@ -22,2 +22,3 @@ var helper = require('./options-helper');

helper.ensureFlagExists('noQuotesForNativeAttributes', options);
helper.ensureFlagExists('avoidDoubleSanitization', options);
helper.ensureSpacesExists(options);

@@ -100,7 +101,7 @@ if (typeof options.spaces === 'number') {

return '<?' + instructionName + writeAttributes(instruction[key][options.attributesKey], options, depth) + '?>';
}
}
var instructionValue = instruction[key] ? instruction[key] : '';
if ('instructionFn' in options) instructionValue = options.instructionFn(instructionValue, key, currentElementName, currentElement);
return '<?' + instructionName + (instructionValue ? ' ' + instructionValue : '') + '?>';
}

@@ -123,3 +124,7 @@

text = '' + text; // ensure Number and Boolean are converted to String
// text = text.replace(/&amp;/g, '&'); // desanitize to avoid double sanitization
if (options.avoidDoubleSanitization) {
text = text.replace(/&amp;/g, '&'); // desanitize to avoid double sanitization
}
text = text.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');

@@ -126,0 +131,0 @@ return 'textFn' in options ? options.textFn(text, currentElementName, currentElement) : text;

{
"name": "xml-js-v2",
"version": "2.0.0",
"version": "2.1.0",
"description": "A fork of xml-js with some improvements. A convertor between XML text and Javascript object / JSON text.",

@@ -5,0 +5,0 @@ "repository": {

@@ -30,3 +30,3 @@ ![XML ⇔ JS/JSON](http://nashwaan.github.io/xml-js/images/logo.svg)

This is a fork of the original [xml-js](https://github.com/nashwaan/xml-js) library by [nashwaan](https://github.com/nashwaan) with some improvements/changes that I need for work. List of these changes:
- When converting from JS to XML, do not leave a string like `&amp;` unchanged, but replace it with `&amp;amp;` instead. This is the correct behaviour and it should have always been this way, the original one caused bugs, for example both `&amp;` and `&` strings were converted to `&amp;`.
- When converting from JS to XML, by default do not leave a string like `&amp;` unchanged, but replace it with `&amp;amp;` instead. This is the correct behaviour and it should have always been this way, the original one caused bugs, for example both `&amp;` and `&` strings were converted to `&amp;`. However, you can use the new flag `avoidDoubleSanitization: true` if you need the original behaviour.

@@ -187,2 +187,4 @@

| `ignoreText` | `false` | Whether to ignore writing texts of the elements. For example, `hi` text in `<a>hi</a>` will be ignored. |
| `avoidDoubleSanitization` | `false` | If set to true, it will not sanitize already escaped characters. If this is not set or set to `false`, then a string like `&amp; &` will be converted to `&amp;amp; &amp;`. If this is set to `true`, then `&amp; &` will be converted to `&amp; &amp;`.
|

@@ -189,0 +191,0 @@ ## Convert XML → JS object / JSON

@@ -93,2 +93,11 @@ export interface Attributes {

noQuotesForNativeAttributes?: boolean
/**
* If set to true, it will not sanitize already escaped characters.
*
* If this is not set or set to `false`, then a string like `&amp; &` will be converted to `&amp;amp; &amp;`.
* If this is set to `true`, then `&amp; &` will be converted to `&amp; &amp;`.
*
* @default false
*/
avoidDoubleSanitization?: boolean
doctypeFn?: (value: string, currentElementName: string, currentElementObj: object) => void;

@@ -95,0 +104,0 @@ instructionFn?: (

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

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