Skip to content

Commit

Permalink
element: don't quote ' and " for vanilla text nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
astro committed Aug 2, 2011
1 parent 2374b30 commit cbc7c85
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/element.js
Expand Up @@ -197,9 +197,9 @@ Element.prototype.write = function(writer) {
if (child.write)
child.write(writer);
else if (typeof child === 'string')
writer(escapeXml(child));
writer(escapeXmlText(child));
else
writer(escapeXml(child.toString()));
writer(escapeXmlText(child.toString()));
});
writer("</");
writer(this.name);
Expand All @@ -216,5 +216,12 @@ function escapeXml(s) {
replace(/'/g, '&apos;');
};

function escapeXmlText(s) {
return s.
replace(/\&/g, '&amp;').
replace(/</g, '&lt;').
replace(/>/g, '&gt;');
};

exports.Element = Element;
exports.escapeXml = escapeXml;

0 comments on commit cbc7c85

Please sign in to comment.