diff --git a/src/js_tests/wirecloud/ioSpec.js b/src/js_tests/wirecloud/ioSpec.js index 656a3197f6..3e4015e130 100644 --- a/src/js_tests/wirecloud/ioSpec.js +++ b/src/js_tests/wirecloud/ioSpec.js @@ -92,6 +92,38 @@ })).toBe(expected); }); + it("should do nothing when using data urls and the forceProxy option", function () { + var original = "data:text/html,lots%20of%20text...

bottom?arg=val"; + + expect(Wirecloud.io.buildProxyURL(original, { + forceProxy: true + })).toBe(original); + }); + + it("should do nothing when using data urls and the forceProxy option (using URL instances)", function () { + var original = new URL("data:text/html,lots%20of%20text...

bottom?arg=val"); + + expect(Wirecloud.io.buildProxyURL(original, { + forceProxy: true + })).toBe(original.toString()); + }); + + it("should do nothing when using blob urls and the forceProxy option", function () { + var original = "blob:d3958f5c-0777-0845-9dcf-2cb28783acaf"; + + expect(Wirecloud.io.buildProxyURL(original, { + forceProxy: true + })).toBe(original); + }); + + it("should do nothing when using blob urls and the forceProxy option (using URL instances)", function () { + var original = new URL("blob:d3958f5c-0777-0845-9dcf-2cb28783acaf"); + + expect(Wirecloud.io.buildProxyURL(original, { + forceProxy: true + })).toBe(original.toString()); + }); + it("should support the parameters option (using URL instances)", function () { var original = new URL("http://server:1234/path"); var expected = "https://wirecloud.example.com/cdp/http/server:1234/path?e=1&b=c"; @@ -141,6 +173,30 @@ })).toBe(expected); }); + it("should ignore the parameters option when using data URL instances", function () { + var original = new URL("data:text/html,lots of text...

bottom?arg=val"); + + expect(Wirecloud.io.buildProxyURL(original, { + method: 'GET', + parameters: { + e: 1, + b: "c" + } + })).toBe(original.toString()); + }); + + it("should ignore the parameters option when using blob URL instances", function () { + var original = new URL("blob:d3958f5c-0777-0845-9dcf-2cb28783acaf"); + + expect(Wirecloud.io.buildProxyURL(original, { + method: 'GET', + parameters: { + e: 1, + b: "c" + } + })).toBe(original.toString()); + }); + }); describe("makeRequest(url, options)", function () { diff --git a/src/wirecloud/platform/static/js/wirecloud/io.js b/src/wirecloud/platform/static/js/wirecloud/io.js index 1da6fb876b..3650d76f95 100644 --- a/src/wirecloud/platform/static/js/wirecloud/io.js +++ b/src/wirecloud/platform/static/js/wirecloud/io.js @@ -232,7 +232,7 @@ var io = {}; io.buildProxyURL = function buildProxyURL(url, options) { - var forceProxy; + var forceProxy, inmemoryurl; options = utils.merge({ method: 'POST', @@ -243,13 +243,14 @@ postBody: null }, options); - forceProxy = !!options.forceProxy; - if (!(url instanceof URL)) { url = new URL(url, Wirecloud.location.domain + Wirecloud.URLs.ROOT_URL); } - if (forceProxy || (options.supportsAccessControl !== true && url.origin !== Wirecloud.location.domain)) { + forceProxy = !!options.forceProxy; + inmemoryurl = ["blob:", "data:"].indexOf(url.protocol) !== -1; + + if (!inmemoryurl && (forceProxy || (options.supportsAccessControl !== true && url.origin !== Wirecloud.location.domain))) { url = Wirecloud.location.domain + Wirecloud.URLs.PROXY.evaluate({protocol: url.protocol.slice(0, -1), domain: url.host, path: url.pathname}) + url.search; } else { @@ -257,7 +258,7 @@ } // Add parameters - if (options.parameters != null && (typeof options.parameters === 'string' || typeof options.parameters === 'object')) { + if (!inmemoryurl && options.parameters != null && (typeof options.parameters === 'string' || typeof options.parameters === 'object')) { if (['PUT', 'POST'].indexOf(options.method) === -1 || options.postBody != null) { if (url.indexOf('?') !== -1) { url += '&' + toQueryString(options.parameters);