When comparing urls remove last '\' symbol if present

Signed-off-by: Vitalii Koshura <lestat.de.lionkur@gmail.com>
This commit is contained in:
Vitalii Koshura 2019-04-17 02:08:54 +03:00
parent b3fc41a416
commit fa4530a784
No known key found for this signature in database
GPG Key ID: CE0DB1726070A5A3
2 changed files with 36 additions and 22 deletions

View File

@ -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; i<gstate.projects.size(); i++) {
PROJECT* p = gstate.projects[i];
string project_url = p->master_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;

View File

@ -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;