From 5234c671a809b250b9ae16dd435cdf0cd3790281 Mon Sep 17 00:00:00 2001 From: Kriegslustig Date: Sat, 26 Dec 2015 20:43:23 +0100 Subject: [PATCH 1/2] Implements an option to prevent the automatic encoding --- lib/xml.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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); } From e4f8bd44748e52a77df292f673f1be538b047704 Mon Sep 17 00:00:00 2001 From: Kriegslustig Date: Tue, 19 Apr 2016 18:44:14 +0200 Subject: [PATCH 2/2] Implement ava tests for the escape option --- test/xml.test.js | 5 +++++ 1 file changed, 5 insertions(+) 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'); +});