]> source.dussan.org Git - nextcloud-server.git/commitdiff
Fix for parsing pretty printed Webdav responses
authorVincent Petry <pvince81@owncloud.com>
Tue, 24 Nov 2015 10:59:00 +0000 (11:59 +0100)
committerThomas Müller <thomas.mueller@tmit.eu>
Tue, 24 Nov 2015 14:26:53 +0000 (15:26 +0100)
Update davclient.js + adjust IE workaround for this

core/js/files/iedavclient.js
core/vendor/davclient.js/lib/client.js

index bc6bce2f9aeb0c84277eac9366eaa139344656db..4fd9a3a3bf4a56eb5aba84acbcd84fd72448c016 100644 (file)
                                        var k = 0;
                                        for (k = 0; k < propNode.childNodes.length; k++) {
                                                var prop = propNode.childNodes[k];
-                                               var value = prop.textContent || prop.text;
-                                               if (prop.childNodes && prop.childNodes.length > 0 && prop.childNodes[0].nodeType === 1) {
-                                                       value = prop.childNodes;
-                                               }
+                                               var value = this._parsePropNode(prop);
                                                propStat.properties['{' + prop.namespaceURI + '}' + (prop.localName || prop.baseName)] = value;
 
                                        }
index 121b5dcab5f7e3cec6b7a53b8a3427e056eac7af..18bbf13f3cd8e474e04dc68e0d75743b098ec92c 100644 (file)
@@ -148,6 +148,33 @@ dav.Client.prototype = {
 
     },
 
+    /**
+     * Parses a property node.
+     *
+     * Either returns a string if the node only contains text, or returns an
+     * array of non-text subnodes.
+     *
+     * @param {Object} propNode node to parse
+     * @return {string|Array} text content as string or array of subnodes, excluding text nodes
+     */
+    _parsePropNode: function(propNode) {
+        var content = null;
+        if (propNode.childNodes && propNode.childNodes.length > 0) {
+            var subNodes = [];
+            // filter out text nodes
+            for (var j = 0; j < propNode.childNodes.length; j++) {
+                var node = propNode.childNodes[j];
+                if (node.nodeType === 1) {
+                    subNodes.push(node);
+                }
+            }
+            if (subNodes.length) {
+                content = subNodes;
+            }
+        }
+
+        return content || propNode.textContent || propNode.text;
+    },
 
     /**
      * Parses a multi-status response body.
@@ -197,11 +224,7 @@ dav.Client.prototype = {
 
                 var propNode = propIterator.iterateNext();
                 while(propNode) {
-                    var content = propNode.textContent;
-                    if (propNode.childNodes && propNode.childNodes.length > 0 && propNode.childNodes[0].nodeType === 1) {
-                        content = propNode.childNodes;
-                    }
-
+                    var content = this._parsePropNode(propNode);
                     propStat.properties['{' + propNode.namespaceURI + '}' + propNode.localName] = content;
                     propNode = propIterator.iterateNext();