From: Aleksander Ɓukasz Date: Thu, 18 Jul 2013 13:19:52 +0000 (+0200) Subject: Don't serialize wlxml meta attribute if it's empty X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/61143e615dfb903cd11c11539b7259cc4bc8b9fe?ds=sidebyside Don't serialize wlxml meta attribute if it's empty --- diff --git a/modules/documentCanvas/canvas/canvas.test3.js b/modules/documentCanvas/canvas/canvas.test3.js index 76ece55..2017a8a 100644 --- a/modules/documentCanvas/canvas/canvas.test3.js +++ b/modules/documentCanvas/canvas/canvas.test3.js @@ -1108,7 +1108,18 @@ describe('Canvas', function() { expect($xmlOut.attr('a')).to.equal('1'); expect($xmlOut.attr('xmlns:dcterms')).to.equal('http://purl.org/dc/terms/'); + }); + + it('doesn\' serialize meta attribute if its empty', function() { + var c; + + c = canvas.fromXML('
'); + c.doc().setWlxmlMetaAttr('uri', ''); + expect($(c.toXML()).attr('meta-uri')).to.equal(undefined, 'overriding attribute with zero length string'); + c = canvas.fromXML('
'); + c.doc().setWlxmlMetaAttr('uri', ''); + expect($(c.toXML()).attr('meta-uri')).to.equal(undefined, 'setting attribute to zero length string'); }); describe('formatting output xml', function() { diff --git a/modules/documentCanvas/canvas/documentElement.js b/modules/documentCanvas/canvas/documentElement.js index 9c2749e..94b8422 100644 --- a/modules/documentCanvas/canvas/documentElement.js +++ b/modules/documentCanvas/canvas/documentElement.js @@ -163,7 +163,8 @@ $.extend(DocumentNodeElement.prototype, { node.attr('class', this.getWlxmlClass()); var meta = this.getWlxmlMetaAttrs(); meta.forEach(function(attr) { - node.attr('meta-' + attr.name, attr.value); + if(attr.value) + node.attr('meta-' + attr.name, attr.value); }); _.keys(this.data('other-attrs') || {}).forEach(function(key) { node.attr(key, this.data('other-attrs')[key]);