Permalink
Browse files

Merge pull request #19 from darashi/fix-text-node-with-empty-string

Fix a problem with text node creation from ''
  • Loading branch information...
2 parents 409ed70 + 8c687d1 commit 0f6b2dfd0c8c6f9fb7696eb0d36287366ab0cbe0 @oozcitak committed Jul 20, 2012
Showing with 7 additions and 2 deletions.
  1. +2 −2 src/XMLFragment.coffee
  2. +5 −0 test/test.coffee
View
4 src/XMLFragment.coffee
@@ -305,7 +305,7 @@ class XMLFragment
# open tag
if pretty
r += space
- if not @value
+ if not @value?
r += '<' + @name
else
r += '' + @value
@@ -319,7 +319,7 @@ class XMLFragment
if @children.length == 0
# empty element
- if not @value
+ if not @value?
r += if @name == '?xml' then '?>' else if @name == '!DOCTYPE' then '>' else '/>'
if pretty
r += newline
View
5 test/test.coffee
@@ -156,3 +156,8 @@ test7 = builder.begin('test7')
.doc().toString()
assert.strictEqual(xml7, test7)
+# Test text node with empty string
+xml9 = '<test9></test9>'
+test9 = builder.begin('test9').text('')
+ .doc().toString()
+assert.strictEqual(xml9, test9)

0 comments on commit 0f6b2df

Please sign in to comment.