Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Encode XML special characters when setting element content

  • Loading branch information...
commit 9038e6083f3167be5938ff6fa6a35345832743e5 1 parent df46046
Vladimir Grichina vgrichina authored defunctzombie committed
Showing with 7 additions and 5 deletions.
  1. +5 −3 src/xml_element.cc
  2. +2 −2 test/element.js
8 src/xml_element.cc
View
@@ -246,7 +246,7 @@ XmlElement::AddPrevSibling(const v8::Arguments& args) {
XmlElement* new_sibling = ObjectWrap::Unwrap<XmlElement>(args[0]->ToObject());
assert(new_sibling);
-
+
new_sibling = element->import_element(new_sibling);
element->add_prev_sibling(new_sibling);
@@ -262,7 +262,7 @@ XmlElement::AddNextSibling(const v8::Arguments& args) {
XmlElement* new_sibling = ObjectWrap::Unwrap<XmlElement>(args[0]->ToObject());
assert(new_sibling);
-
+
new_sibling = element->import_element(new_sibling);
element->add_next_sibling(new_sibling);
@@ -393,7 +393,9 @@ XmlElement::get_path() {
void
XmlElement::set_content(const char* content) {
- xmlNodeSetContent(xml_obj, (const xmlChar*)content);
+ xmlChar *encoded = xmlEncodeSpecialChars(xml_obj->doc, (const xmlChar*)content);
+ xmlNodeSetContent(xml_obj, encoded);
+ xmlFree(encoded);
}
v8::Handle<v8::Value>
4 test/element.js
View
@@ -15,8 +15,8 @@ module.exports.setters = function(assert) {
// change content
assert.equal('', elem.text());
- elem.text('content');
- assert.equal('content', elem.text());
+ elem.text('content && more content <>');
+ assert.equal('content && more content <>', elem.text());
// change name
assert.equal('name1', elem.name());
Please sign in to comment.
Something went wrong with that request. Please try again.