Don't serialize wlxml meta attribute if it's empty
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Thu, 18 Jul 2013 13:19:52 +0000 (15:19 +0200)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Thu, 18 Jul 2013 13:19:52 +0000 (15:19 +0200)
modules/documentCanvas/canvas/canvas.test3.js
modules/documentCanvas/canvas/documentElement.js

index 76ece55..2017a8a 100644 (file)
@@ -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/');
 
             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('<section class="uri" meta-uri="some.uri"></section>');
+            c.doc().setWlxmlMetaAttr('uri', '');
+            expect($(c.toXML()).attr('meta-uri')).to.equal(undefined, 'overriding attribute with zero length string');
 
 
+            c = canvas.fromXML('<section class="uri"></section>');
+            c.doc().setWlxmlMetaAttr('uri', '');
+            expect($(c.toXML()).attr('meta-uri')).to.equal(undefined, 'setting attribute to zero length string');
         });
 
         describe('formatting output xml', function() {
         });
 
         describe('formatting output xml', function() {
index 9c2749e..94b8422 100644 (file)
@@ -163,7 +163,8 @@ $.extend(DocumentNodeElement.prototype, {
             node.attr('class', this.getWlxmlClass());
         var meta = this.getWlxmlMetaAttrs();
         meta.forEach(function(attr) {
             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]);
         });
         _.keys(this.data('other-attrs') || {}).forEach(function(key) {
             node.attr(key, this.data('other-attrs')[key]);