Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/xml.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ var escapeForXML = require('./escapeForXML');
var Stream = require('stream').Stream;

var DEFAULT_INDENT = ' ';
var SHOULD_ESCAPE = true

function xml(input, options) {

Expand All @@ -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) {
Expand Down Expand Up @@ -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);
}

});
Expand All @@ -206,7 +208,7 @@ function resolve(data, indent, indent_count) {

default:
//string
content.push(escapeForXML(values));
content.push(SHOULD_ESCAPE ? escapeForXML(values) : values);

}

Expand Down
5 changes: 5 additions & 0 deletions test/xml.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,8 @@ test('xml declaration options', t => {
t.is(xml([{a: 'test'}], {declaration: true, indent: '\n'}), '<?xml version="1.0" encoding="UTF-8"?>\n<a>test</a>');
t.is(xml([{a: 'test'}], {}), '<a>test</a>');
});

test('escape option', t => {
t.is(xml([ { x: '<a>test</a>' } ], { escape: false }), '<x><a>test</a></x>');
t.is(xml([ { x: [ { _attr: { a: 'x' } }, '<a>test</a>' ] } ], { escape: false }), '<x a="x"><a>test</a></x>');
});