From d2ed82f28405f09f4f1710bcfd603dc3cf04d277 Mon Sep 17 00:00:00 2001 From: Javier Perez Date: Fri, 3 Feb 2017 19:41:36 -0400 Subject: [PATCH 1/2] Extracted XMLHttpRequest object instantiation into a separate method. Added a test and workaround for Visualforce's Sarissa library XMLHttpRequest constructor masking. --- forcetk.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/forcetk.js b/forcetk.js index 7fd2918..b7245d2 100644 --- a/forcetk.js +++ b/forcetk.js @@ -80,6 +80,17 @@ if (forcetk.Client === undefined) { this.asyncAjax = true; }; + /** + * Creates an AJAX request object. Can be overridden for particular implementations. + */ + forcetk.Client.prototype.getXHR = function () { + if (window && window.Sarissa && window.Sarissa.originalXMLHttpRequest) { + return new window.Sarissa.originalXMLHttpRequest(); + } else { + return new XMLHttpRequest(); + } + }; + /** * Set a refresh token in the client. * @param refreshToken an OAuth refresh token @@ -211,7 +222,7 @@ if (forcetk.Client === undefined) { 'use strict'; var that = this, url = (this.visualforce ? '' : this.instanceUrl) + path, - request = new XMLHttpRequest(); + request = this.getXHR(); request.open("GET", (this.proxyUrl !== null && !this.visualforce) ? this.proxyUrl : url, true); request.responseType = "arraybuffer"; @@ -293,7 +304,7 @@ if (forcetk.Client === undefined) { "\n\n" + "--boundary_" + boundary + "--" ], {type : 'multipart/form-data; boundary=\"boundary_' + boundary + '\"'}), - request = new XMLHttpRequest(); + request = this.getXHR(); request.open("POST", (this.proxyUrl !== null && !this.visualforce) ? this.proxyUrl : url, this.asyncAjax); From 7b290f9bfd76be0c60c199c4e8b24787167941f4 Mon Sep 17 00:00:00 2001 From: Javier Perez Date: Mon, 17 Apr 2017 19:40:08 -0400 Subject: [PATCH 2/2] Reapply fix made in commit 217010d that prevents file corruption from additional line return characters appended to the file contents. --- forcetk.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/forcetk.js b/forcetk.js index b7245d2..5b387d3 100644 --- a/forcetk.js +++ b/forcetk.js @@ -301,7 +301,7 @@ if (forcetk.Client === undefined) { + "Content-Disposition: form-data; name=\"" + payloadField + "\"; filename=\"" + filename + "\"\n\n", payload, - "\n\n" + "\n" + "--boundary_" + boundary + "--" ], {type : 'multipart/form-data; boundary=\"boundary_' + boundary + '\"'}), request = this.getXHR();