Skip to content
This repository was archived by the owner on Jan 7, 2021. It is now read-only.

Commit c942e72

Browse files
committed
Prevent double sanitizing.
Apparently, node-expat already unsanitizes the text for us when parsing xml before handing it off. So, we don't need to do it again.
1 parent 1779428 commit c942e72

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

lib/xml2json.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,10 @@ function endElement(name) {
6060
currentObject['$t'] = currentObject['$t'].trim()
6161
}
6262

63-
if (options.sanitize) {
64-
currentObject['$t'] = sanitizer.sanitize(currentObject['$t'], true);
65-
}
63+
// node-expat already reverse sanitizes it whether we like it or not
64+
//if (options.sanitize) {
65+
// currentObject['$t'] = sanitizer.sanitize(currentObject['$t'], true);
66+
//}
6667

6768
currentObject['$t'] = coerce(currentObject['$t'],name);
6869
}

test/test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,28 @@ describe('xml2json', function () {
129129
done();
130130
});
131131

132+
it('does doesnt double sanitize', function (done) {
133+
134+
var json = internals.readFixture('xmlsanitize3.json');
135+
var result = parser.toXml(json, {sanitize: true});
136+
var xml = internals.readFixture('xmlsanitize3.xml');
137+
138+
expect(result).to.equal(xml);
139+
140+
done();
141+
});
142+
143+
it('does doesnt double unsanitize', function (done) {
144+
145+
var xml = internals.readFixture('xmlsanitize3.xml');
146+
var result = parser.toJson(xml, {sanitize: true, reversible: true});
147+
var json = internals.readFixture('xmlsanitize3.json');
148+
149+
expect(result).to.equal(json);
150+
151+
done();
152+
});
153+
132154
it('throws error on bad options', function (done) {
133155

134156
var throws = function() {

0 commit comments

Comments
 (0)