From fa4530a784632cce904c4b2beffc548f5a375d7d Mon Sep 17 00:00:00 2001 From: Vitalii Koshura Date: Wed, 17 Apr 2019 02:08:54 +0300 Subject: [PATCH] When comparing urls remove last '\' symbol if present Signed-off-by: Vitalii Koshura --- client/gui_rpc_server_ops.cpp | 19 +++++++++++------ clientgui/ProjectInfoPage.cpp | 39 +++++++++++++++++++++-------------- 2 files changed, 36 insertions(+), 22 deletions(-) diff --git a/client/gui_rpc_server_ops.cpp b/client/gui_rpc_server_ops.cpp index d5d7364cbf..4babe5ee00 100644 --- a/client/gui_rpc_server_ops.cpp +++ b/client/gui_rpc_server_ops.cpp @@ -878,30 +878,37 @@ static void handle_project_attach(GUI_RPC_CONN& grc) { // there is no reason to connect to secure address project // if we're already connected to the non-secure address // or vice versa + // also clear last '/' character if present - const std::string http = "http://"; - const std::string https = "https://"; + const string http = "http://"; + const string https = "https://"; string new_project_url = url; size_t pos = new_project_url.find(http); - if (pos != std::string::npos) { + if (pos != string::npos) { new_project_url.erase(pos, http.length()); } - else if ((pos = new_project_url.find(https)) != std::string::npos) { + else if ((pos = new_project_url.find(https)) != string::npos) { new_project_url.erase(pos, https.length()); } + if (new_project_url.length() >= 1 && new_project_url[new_project_url.length() - 1] == '/') { + new_project_url.erase(new_project_url.length() - 1, 1); + } for (i=0; imaster_url; pos = project_url.find(http); - if (pos != std::string::npos) { + if (pos != string::npos) { project_url.erase(pos, http.length()); } - else if ((pos = project_url.find(https)) != std::string::npos) { + else if ((pos = project_url.find(https)) != string::npos) { project_url.erase(pos, https.length()); } + if (project_url.length() >= 1 && project_url[project_url.length() - 1] == '/') { + project_url.erase(project_url.length() - 1, 1); + } if (new_project_url == project_url) { already_attached = true; diff --git a/clientgui/ProjectInfoPage.cpp b/clientgui/ProjectInfoPage.cpp index ead4934fe0..c4968f5940 100644 --- a/clientgui/ProjectInfoPage.cpp +++ b/clientgui/ProjectInfoPage.cpp @@ -816,32 +816,39 @@ void CProjectInfoPage::OnPageChanging( wxWizardExEvent& event ) { // Check if we are already attached to that project: const std::string http = "http://"; const std::string https = "https://"; + + std::string new_project_url = (const char*)m_strProjectURL.mb_str(); + canonicalize_master_url(new_project_url); + // remove http(s):// at the beginning of project address + // there is no reason to connect to secure address project + // if we're already connected to the non-secure address + // or vice versa + // also clear last '/' character if present + size_t pos = new_project_url.find(http); + if (pos != std::string::npos) { + new_project_url.erase(pos, http.length()); + } + else if ((pos = new_project_url.find(https)) != std::string::npos) { + new_project_url.erase(pos, https.length()); + } + if (new_project_url.length() >= 1 && new_project_url[new_project_url.length() - 1] == '/') { + new_project_url.erase(new_project_url.length() - 1, 1); + } for (int i = 0; i < pDoc->GetProjectCount(); ++i) { PROJECT* project = pDoc->project(i); if (project) { - std::string project_url = project->master_url; - std::string new_project_url = (const char*)m_strProjectURL.mb_str(); + std::string project_url = project->master_url; canonicalize_master_url(project_url); - canonicalize_master_url(new_project_url); - // remove http(s):// at the beginning of project address - // there is no reason to connect to secure address project - // if we're already connected to the non-secure address - // or vice versa - size_t pos = project_url.find(http); - if (pos != std::string::npos) { + if ((pos = project_url.find(http)) != std::string::npos) { project_url.erase(pos, http.length()); } else if ((pos = project_url.find(https)) != std::string::npos) { project_url.erase(pos, https.length()); } - - if ((pos = new_project_url.find(http)) != std::string::npos) { - new_project_url.erase(pos, http.length()); - } - else if ((pos = new_project_url.find(https)) != std::string::npos) { - new_project_url.erase(pos, https.length()); - } + if (project_url.length() >= 1 && project_url[project_url.length() - 1] == '/') { + project_url.erase(project_url.length() - 1, 1); + } if (project_url == new_project_url) { bAlreadyAttached = true;