[Pkg-javascript-commits] [ltx] 176/469: element: serialize non-string child nodes + test
Jonas Smedegaard
dr at jones.dk
Wed Aug 31 13:01:29 UTC 2016
This is an automated email from the git hooks/post-receive script.
js pushed a commit to branch master
in repository ltx.
commit 7085c0cd90563f3ba53a271bf00935743997a96e
Author: Astro <astro at spaceboyz.net>
Date: Wed Apr 27 13:46:57 2011 +0200
element: serialize non-string child nodes + test
---
lib/element.js | 8 +++++---
test/test_element.js | 8 ++++++++
2 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/lib/element.js b/lib/element.js
index 8e0e981..8d0441b 100644
--- a/lib/element.js
+++ b/lib/element.js
@@ -194,10 +194,12 @@ Element.prototype.write = function(writer) {
} else {
writer(">");
this.children.forEach(function(child) {
- if (typeof child == 'string')
- writer(escapeXml(child));
- else
+ if (child.write)
child.write(writer);
+ else if (typeof child === 'string')
+ writer(escapeXml(child));
+ else
+ writer(escapeXml(child.toString()));
});
writer("</");
writer(this.name);
diff --git a/test/test_element.js b/test/test_element.js
index 27bed1a..17de103 100644
--- a/test/test_element.js
+++ b/test/test_element.js
@@ -25,6 +25,14 @@ vows.describe('ltx').addBatch({
'serialize an element with text to entities': function() {
var e = new ltx.Element('e').t('1 < 2').root();
assert.equal(e.toString(), '<e>1 < 2</e>');
+ },
+ 'serialize an element with a number attribute': function() {
+ var e = new ltx.Element('e', { a: 23 });
+ assert.equal(e.toString(), '<e a="23"/>');
+ },
+ 'serialize an element with number contents': function() {
+ var e = new ltx.Element('e').t(23);
+ assert.equal(e.toString(), '<e>23</e>');
}
},
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/ltx.git
More information about the Pkg-javascript-commits
mailing list