Skip to content

Commit

Permalink
fix: double escaping (libxmljs#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
marudor committed Oct 30, 2019
1 parent 60afe06 commit edd08d8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
8 changes: 1 addition & 7 deletions src/xml_text.cc
Expand Up @@ -39,13 +39,7 @@ NAN_METHOD(XmlText::New)
Nan::Utf8String contentRaw(contentOpt);
const char *content = (contentRaw.length()) ? *contentRaw : NULL;

xmlChar *encodedContent = content ? xmlEncodeSpecialChars(document->xml_obj, (const xmlChar *)content) : NULL;

xmlNode *textNode = xmlNewDocText(document->xml_obj, encodedContent);
if (encodedContent)
{
xmlFree(encodedContent);
}
xmlNode *textNode = xmlNewDocText(document->xml_obj, (const xmlChar *)content);

XmlText *element = new XmlText(textNode);
textNode->_private = element;
Expand Down
11 changes: 10 additions & 1 deletion test/text.js
Expand Up @@ -77,6 +77,16 @@ module.exports.addChild = function(assert) {
assert.done();
};

module.exports.addChildEscaping = function(assert) {
var doc = libxml.parseXmlString("<p></p>");

doc.root().addChild(libxml.Text(doc, "x&x"));

assert.equal('<p>x&amp;x</p>', doc.root().toString());

assert.done();
}

module.exports.addSiblings = function(assert) {
var doc = libxml.Document();

Expand Down Expand Up @@ -132,4 +142,3 @@ module.exports.add_next_sibling_merge_text = function(assert) {

assert.done();
};

0 comments on commit edd08d8

Please sign in to comment.