Fixing xml output - entities
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Thu, 25 Jul 2013 08:02:26 +0000 (10:02 +0200)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Thu, 25 Jul 2013 12:35:08 +0000 (14:35 +0200)
modules/documentCanvas/canvas/canvas.test3.js
modules/documentCanvas/canvas/documentElement.js

index eeab1b2..565e4b0 100644 (file)
@@ -1122,6 +1122,21 @@ describe('Canvas', function() {
             expect($(c.toXML()).attr('meta-uri')).to.equal(undefined, 'setting attribute to zero length string');
         });
 
             expect($(c.toXML()).attr('meta-uri')).to.equal(undefined, 'setting attribute to zero length string');
         });
 
+        describe('output xml', function() {
+            it('keeps entities intact', function() {
+                var xmlIn = '<section>&lt; &gt;</section>',
+                    c = canvas.fromXML(xmlIn),
+                    xmlOut = c.toXML();
+                expect(xmlOut).to.equal(xmlIn);
+            });
+            it('keeps entities intact when they form html/xml', function() {
+                var xmlIn = '<section>&lt;abc&gt;</section>',
+                    c = canvas.fromXML(xmlIn),
+                    xmlOut = c.toXML();
+                expect(xmlOut).to.equal(xmlIn);
+            });
+        });
+
         describe('formatting output xml', function() {
             /*it('keeps white spaces at the edges of input xml', function() {
                 var xmlIn = '  <section></section>  ',
         describe('formatting output xml', function() {
             /*it('keeps white spaces at the edges of input xml', function() {
                 var xmlIn = '  <section></section>  ',
index 8ef918a..29b07df 100644 (file)
@@ -210,7 +210,9 @@ $.extend(DocumentNodeElement.prototype, {
 
         for(var i = children.length - 1; i >= 0; i--) {
             childParts = children[i].toXML(level + 1);
 
         for(var i = children.length - 1; i >= 0; i--) {
             childParts = children[i].toXML(level + 1);
-            
+            if(typeof childParts === 'string')
+                childParts = [document.createTextNode(childParts)];
+
             if(containsPrefixAndSuffix(i) && children[i] instanceof DocumentTextElement) {
                 $(node.contents()[0]).after(childParts);
             } else {
             if(containsPrefixAndSuffix(i) && children[i] instanceof DocumentTextElement) {
                 $(node.contents()[0]).after(childParts);
             } else {