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

Also run sanitize on the content when converting from xml to json. #129

Merged
merged 7 commits into from
Jul 13, 2017

Conversation

ehoogerbeets
Copy link
Contributor

Previously, the content was unsanitized when the data was converted from xml to json, but not sanitized when converted from json to xml. This is corrected now so that the conversion is reversible.

Previously, the content was unsanitized when the data was converted
from json to xml, but not when converted from xml to json. This is
corrected now so that the conversion is reversible.
@ehoogerbeets
Copy link
Contributor Author

@c4milo Please have a look at this new PR for you in xml2json. I did this change because I am representing HTML strings in an XLIFF file (XML Localization Interchange File Format) and the embedded HTML tags were screwing up the XML syntax without this 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.
@c4milo
Copy link
Contributor

c4milo commented Oct 24, 2016

Nice, thanks for this, I'll review tomorrow.

@ehoogerbeets
Copy link
Contributor Author

@c4milo review?

lib/xml2json.js Outdated
if (options.sanitize) {
currentObject['$t'] = sanitizer.sanitize(currentObject['$t'], true);
}
// node-expat already reverse sanitizes it whether we like it or not
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would just remove these comments, leaving them in the commit message instead.

@c4milo
Copy link
Contributor

c4milo commented Nov 22, 2016

Apologies it took me so long, it looks good to me in general. I Only commented on a minor thing.

lib/json2xml.js Outdated
}
this.xml += ' ' + key + '="' + val + '"';
}
ToXml.prototype.addTextContent = function(text) {
this.completeTag();
this.xml += text;
this.xml += (this.options.sanitize ? sanitizer.sanitize(text) : text);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use multiple lines so a step by step debugging can be possible.

@antti-manninen
Copy link

Is this pull request still alive? This would be really useful fix.

@ehoogerbeets
Copy link
Contributor Author

Hi Anti, I didn't see c4milo's response to this. I'll work on it now and resolve the merge conflict.

var result = parser.toJson(xml, {sanitize: true, reversible: true});
var json = internals.readFixture('xmlsanitize3.json');

expect(result).to.equal(json);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Travis is failing because done() is missing from this test case.

@ehoogerbeets
Copy link
Contributor Author

Okay, ready to merge.

@c4milo c4milo merged commit 3c8552c into buglabs:master Jul 13, 2017
@antti-manninen
Copy link

c4milo, can you publish these changes to npm also?

ehoogerbeets added a commit to ehoogerbeets/node-xml2json that referenced this pull request Nov 15, 2017
Merge pull request buglabs#129 from ehoogerbeets/master
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants