Browse Source

[filebrowser] Fixes modal upload in IE9 and IE10

Added CSRF hidden input for the iframe fallback
Fixed check on __proto__
Enrico Berti 10 years ago
parent
commit
446c06e1de
1 changed files with 9 additions and 3 deletions
  1. 9 3
      desktop/core/src/desktop/static/desktop/ext/js/fileuploader.js

+ 9 - 3
desktop/core/src/desktop/static/desktop/ext/js/fileuploader.js

@@ -1042,6 +1042,12 @@ qq.extend(qq.UploadHandlerForm.prototype, {
         dest.value = params.dest;
         form.appendChild(dest);
 
+        var csrfmiddlewaretoken = document.createElement('input');
+        csrfmiddlewaretoken.type = 'hidden';
+        csrfmiddlewaretoken.name = 'csrfmiddlewaretoken';
+        csrfmiddlewaretoken.value = $.cookie('csrftoken');
+        form.appendChild(csrfmiddlewaretoken);
+
         var self = this;
         this._attachLoadEvent(iframe, function(){
             self.log('iframe loaded');
@@ -1095,10 +1101,10 @@ qq.extend(qq.UploadHandlerForm.prototype, {
             response;
 
         this.log("converting iframe's innerHTML to JSON");
-        this.log("innerHTML = " + doc.body.innerHTML);
+        this.log("innerHTML = " + $(doc.body.innerHTML).text());
 
         try {
-            response = eval("(" + doc.body.innerHTML + ")");
+            response = eval("(" + $(doc.body.innerHTML).text() + ")");
         } catch(err){
             response = {};
         }
@@ -1182,7 +1188,7 @@ qq.extend(qq.UploadHandlerXhr.prototype, {
         // HUE-815: [fb] Upload button does not work in Firefox 3.6
         // see https://github.com/valums/ajax-upload/issues/91
         //if (!(file instanceof File)){
-        if (!(file instanceof File || file.__proto__.constructor.name == 'File' || file instanceof Object) ){
+        if (!(file instanceof File || (file.__proto__ && file.__proto__.constructor.name == 'File') || file instanceof Object) ){
             throw new Error('Passed obj in not a File (in qq.UploadHandlerXhr)');
         }