diff --git a/lib/xml.js b/lib/xml.js
index 01a5654..79a88d8 100644
--- a/lib/xml.js
+++ b/lib/xml.js
@@ -2,6 +2,7 @@ var escapeForXML = require('./escapeForXML');
var Stream = require('stream').Stream;
var DEFAULT_INDENT = ' ';
+var SHOULD_ESCAPE = true
function xml(input, options) {
@@ -19,6 +20,7 @@ function xml(input, options) {
: options.indent,
instant = true;
+ SHOULD_ESCAPE = options.escape === undefined ? SHOULD_ESCAPE : options.escape;
function delay (func) {
if (!instant) {
@@ -194,7 +196,7 @@ function resolve(data, indent, indent_count) {
//string
content.pop();
isStringContent=true;
- content.push(escapeForXML(value));
+ content.push(SHOULD_ESCAPE ? escapeForXML(value) : value);
}
});
@@ -206,7 +208,7 @@ function resolve(data, indent, indent_count) {
default:
//string
- content.push(escapeForXML(values));
+ content.push(SHOULD_ESCAPE ? escapeForXML(values) : values);
}
diff --git a/test/xml.test.js b/test/xml.test.js
index 845e79d..1477b45 100644
--- a/test/xml.test.js
+++ b/test/xml.test.js
@@ -148,3 +148,8 @@ test('xml declaration options', t => {
t.is(xml([{a: 'test'}], {declaration: true, indent: '\n'}), '\ntest');
t.is(xml([{a: 'test'}], {}), 'test');
});
+
+test('escape option', t => {
+ t.is(xml([ { x: 'test' } ], { escape: false }), 'test');
+ t.is(xml([ { x: [ { _attr: { a: 'x' } }, 'test' ] } ], { escape: false }), 'test');
+});