From: Aleksander Ɓukasz Date: Wed, 20 Nov 2013 12:31:45 +0000 (+0100) Subject: smartxml: fix - handle creation of an empty text node X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/11ee4548da5e5e4297d020356c6d1014475d6b05?hp=b3f4fee8a2f01bf946bf28f9abd8b782e67dc186 smartxml: fix - handle creation of an empty text node --- diff --git a/src/smartxml/smartxml.js b/src/smartxml/smartxml.js index 6f3d7de..0a1a354 100644 --- a/src/smartxml/smartxml.js +++ b/src/smartxml/smartxml.js @@ -372,7 +372,7 @@ $.extend(Document.prototype, Backbone.Events, { createDocumentNode: function(from) { if(!(from instanceof Node)) { - if(from.text) { + if(from.text !== undefined) { from = document.createTextNode(from.text); } else { var node = $('<' + from.tagName + '>'); diff --git a/src/smartxml/smartxml.test.js b/src/smartxml/smartxml.test.js index ccaf0ef..a0c1af4 100644 --- a/src/smartxml/smartxml.test.js +++ b/src/smartxml/smartxml.test.js @@ -51,6 +51,14 @@ describe('smartxml', function() { expect(doc.containsNode(a)).to.equal(true, 'contains Element Node'); expect(doc.containsNode(text)).to.equal(true, 'contains Text Node'); }); + + it('creates text nodes', function() { + var doc = getDocumentFromXML('
'), + emptyTextNode = doc.createDocumentNode({text:''}), + nonEmptyTextNode = doc.createDocumentNode({text: 'alice'}); + expect(emptyTextNode.getText()).to.equal('', 'empty ok'); + expect(nonEmptyTextNode.getText()).to.equal('alice', 'non empty ok'); + }); }); describe('Basic ElementNode properties', function() {