Comparing version 2.0.0 to 2.1.0
@@ -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(/&/g, '&'); // desanitize to avoid double sanitization | ||
if (options.avoidDoubleSanitization) { | ||
text = text.replace(/&/g, '&'); // desanitize to avoid double sanitization | ||
} | ||
text = text.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>'); | ||
@@ -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 `&` unchanged, but replace it with `&amp;` instead. This is the correct behaviour and it should have always been this way, the original one caused bugs, for example both `&` and `&` strings were converted to `&`. | ||
- When converting from JS to XML, by default do not leave a string like `&` unchanged, but replace it with `&amp;` instead. This is the correct behaviour and it should have always been this way, the original one caused bugs, for example both `&` and `&` strings were converted to `&`. 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 `& &` will be converted to `&amp; &`. If this is set to `true`, then `& &` will be converted to `& &`. | ||
| | ||
@@ -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 `& &` will be converted to `&amp; &`. | ||
* If this is set to `true`, then `& &` will be converted to `& &`. | ||
* | ||
* @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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
414038
8645
400