[FIX] json_node_to_xml: whitespaces wrongly inserted around text nodes causing bugs...
authorFabien Meghazi <fme@openerp.com>
Tue, 25 Oct 2011 16:35:31 +0000 (18:35 +0200)
committerFabien Meghazi <fme@openerp.com>
Tue, 25 Oct 2011 16:35:31 +0000 (18:35 +0200)
bzr revid: fme@openerp.com-20111025163531-nxr8gb4j2f7wne2a

addons/web/static/src/js/views.js

index 78abe6a..41be7a1 100644 (file)
@@ -953,19 +953,19 @@ session.web.View = session.web.Widget.extend(/** @lends session.web.View# */{
     }
 });
 
-session.web.json_node_to_xml = function(node, single_quote, indent) {
+session.web.json_node_to_xml = function(node, human_readable, indent) {
     // For debugging purpose, this function will convert a json node back to xml
     // Maybe usefull for xml view editor
+    indent = indent || 0;
+    var sindent = (human_readable ? (new Array(indent + 1).join('\t')) : ''),
+        r = sindent + '<' + node.tag,
+        cr = human_readable ? '\n' : '';
 
     if (typeof(node) === 'string') {
-        return node;
-    }
-    else if (typeof(node.tag) !== 'string' || !node.children instanceof Array || !node.attrs instanceof Object) {
+        return sindent + node;
+    } else if (typeof(node.tag) !== 'string' || !node.children instanceof Array || !node.attrs instanceof Object) {
         throw("Node a json node");
     }
-    indent = indent || 0;
-    var sindent = new Array(indent + 1).join('\t'),
-        r = sindent + '<' + node.tag;
     for (var attr in node.attrs) {
         var vattr = node.attrs[attr];
         if (typeof(vattr) !== 'string') {
@@ -973,19 +973,19 @@ session.web.json_node_to_xml = function(node, single_quote, indent) {
             vattr = JSON.stringify(vattr);
         }
         vattr = vattr.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
-        if (single_quote) {
+        if (human_readable) {
             vattr = vattr.replace(/&quot;/g, "'");
         }
         r += ' ' + attr + '="' + vattr + '"';
     }
     if (node.children && node.children.length) {
-        r += '>\n';
+        r += '>' + cr;
         var childs = [];
         for (var i = 0, ii = node.children.length; i < ii; i++) {
-            childs.push(session.web.json_node_to_xml(node.children[i], single_quote, indent + 1));
+            childs.push(session.web.json_node_to_xml(node.children[i], human_readable, indent + 1));
         }
-        r += childs.join('\n');
-        r += '\n' + sindent + '</' + node.tag + '>';
+        r += childs.join(cr);
+        r += cr + sindent + '</' + node.tag + '>';
         return r;
     } else {
         return r + '/>';