From 5bd22f5afe5337d60847b332ddd65ffc70daf572 Mon Sep 17 00:00:00 2001 From: Piotr Gawron <piotr.gawron@uni.lu> Date: Tue, 16 Oct 2018 14:31:12 +0200 Subject: [PATCH] urls don't contain double / characters --- frontend-js/src/main/js/ServerConnector.js | 8 ++++---- frontend-js/src/test/js/ServerConnector-mock.js | 12 +++++++++--- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/frontend-js/src/main/js/ServerConnector.js b/frontend-js/src/main/js/ServerConnector.js index 01b15bbea0..97d8b5d6e6 100644 --- a/frontend-js/src/main/js/ServerConnector.js +++ b/frontend-js/src/main/js/ServerConnector.js @@ -370,7 +370,7 @@ ServerConnector.getApiUrl = function (paramObj) { var result = paramObj.url; if (result === undefined) { - result = this.getApiBaseUrl() + "/" + type; + result = this.getApiBaseUrl() + type; } if (params !== "") { result += "?" + params; @@ -614,13 +614,13 @@ ServerConnector.getReferenceGenomeOrganismsUrl = function (queryParams, filterPa ServerConnector.loginUrl = function () { return this.getApiUrl({ - type: "/doLogin" + type: "doLogin" }); }; ServerConnector.logoutUrl = function () { return this.getApiUrl({ - type: "/doLogout" + type: "doLogout" }); }; @@ -892,7 +892,7 @@ ServerConnector.getCreateFileUrl = function () { }; ServerConnector.getFileUrl = function (queryParams) { return this.getApiUrl({ - url: this.getFilesUrl() + "/" + queryParams.id + url: this.getFilesUrl() + queryParams.id }); }; ServerConnector.getUploadFileUrl = function (queryParams) { diff --git a/frontend-js/src/test/js/ServerConnector-mock.js b/frontend-js/src/test/js/ServerConnector-mock.js index fa5f72b1f0..ca183829e0 100644 --- a/frontend-js/src/test/js/ServerConnector-mock.js +++ b/frontend-js/src/test/js/ServerConnector-mock.js @@ -10,6 +10,8 @@ var NetworkError = require('../../main/js/NetworkError'); var fs = require('fs'); var request = require('request'); +var chai = require('chai'); +var assert = chai.assert; var ServerConnectorMock = OriginalServerConnector; @@ -19,6 +21,7 @@ function replaceAsterisk(str) { function urlToFileName(url) { var result = url; + assert.equal(-1, url.indexOf("//"), "Invalid url: " + url); var token = OriginalServerConnector.getSessionData().getToken(); if (token !== undefined && token !== "" && url.indexOf("./testFiles/apiCalls") === 0) { if (!result.endsWith("&") && !result.endsWith("_")) { @@ -47,7 +50,10 @@ ServerConnectorMock._sendRequest = function (params) { if (prefix === "GET") { prefix = ""; } else { - prefix = "/" + prefix + "_"; + prefix = prefix + "_"; + if (!url.endsWith("/")) { + prefix = "/" + prefix; + } } var suffix = ""; if (params.form !== undefined) { @@ -92,9 +98,9 @@ ServerConnectorMock.getApiBaseUrl = function () { var originalGetApiUrl = OriginalServerConnector.getApiUrl; ServerConnectorMock.getApiUrl = function (paramObj) { - // replace '?' with '/' + // replace '?' (or '/?') with '/' // the call is done on ServerConnectorObject (so 'this' is set properly) - return originalGetApiUrl.call(this, paramObj).replace(/\?/g, '/'); + return originalGetApiUrl.call(this, paramObj).replace(/\/?\?/g, '/'); }; module.exports = ServerConnectorMock; -- GitLab