Merge pull request #2732 from AenBleidd/add_project_compare_url_tune

[Manager] Fix project urls comparison
This commit is contained in:
lfield 2019-04-17 10:01:27 +02:00 committed by GitHub
commit 3255b4e722
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 69 additions and 5 deletions

View File

@ -880,9 +880,46 @@ static void handle_project_attach(GUI_RPC_CONN& grc) {
}
}
// 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
const string http = "http://";
const string https = "https://";
string new_project_url = url;
size_t pos = new_project_url.find(http);
if (pos != string::npos) {
new_project_url.erase(pos, http.length());
}
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];
if (url == p->master_url) already_attached = true;
string project_url = p->master_url;
pos = project_url.find(http);
if (pos != string::npos) {
project_url.erase(pos, http.length());
}
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;
break;
}
}
if (already_attached) {

View File

@ -814,15 +814,42 @@ 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);
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 (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;
break;