Skip "user@" when finding hostname in url
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
diff --git a/src/netops.c b/src/netops.c
index 59e6bda..5623ca9 100644
--- a/src/netops.c
+++ b/src/netops.c
@@ -580,10 +580,12 @@ int gitno_select_in(gitno_buffer *buf, long int sec, long int usec)
int gitno_extract_host_and_port(char **host, char **port, const char *url, const char *default_port)
{
- char *colon, *slash, *delim;
+ char *colon, *slash, *at, *delim;
+ const char *start;
colon = strchr(url, ':');
slash = strchr(url, '/');
+ at = strchr(url, '@');
if (slash == NULL) {
giterr_set(GITERR_NET, "Malformed URL: missing /");
@@ -598,7 +600,9 @@ int gitno_extract_host_and_port(char **host, char **port, const char *url, const
GITERR_CHECK_ALLOC(*port);
delim = colon == NULL ? slash : colon;
- *host = git__strndup(url, delim - url);
+ start = at == NULL && at < slash ? url : at+1;
+
+ *host = git__strndup(start, delim - start);
GITERR_CHECK_ALLOC(*host);
return 0;
diff --git a/tests-clar/online/clone.c b/tests-clar/online/clone.c
index 8226bd0..12b9e03 100644
--- a/tests-clar/online/clone.c
+++ b/tests-clar/online/clone.c
@@ -6,6 +6,7 @@
#define LIVE_REPO_URL "http://github.com/libgit2/TestGitRepository"
#define LIVE_EMPTYREPO_URL "http://github.com/libgit2/TestEmptyRepository"
+#define BB_REPO_URL "https://libgit2@bitbucket.org/libgit2/testgitrepository.git"
static git_repository *g_repo;
static git_clone_options g_options;
@@ -150,4 +151,20 @@ void test_online_clone__credentials(void)
g_options.cred_acquire_payload = &user_pass;
cl_git_pass(git_clone(&g_repo, remote_url, "./foo", &g_options));
+ git_repository_free(g_repo); g_repo = NULL;
+ cl_fixture_cleanup("./foo");
+}
+
+void test_online_clone__bitbucket_style(void)
+{
+ git_cred_userpass_payload user_pass = {
+ "libgit2", "libgit2"
+ };
+
+ g_options.cred_acquire_cb = git_cred_userpass;
+ g_options.cred_acquire_payload = &user_pass;
+
+ cl_git_pass(git_clone(&g_repo, BB_REPO_URL, "./foo", &g_options));
+ git_repository_free(g_repo); g_repo = NULL;
+ cl_fixture_cleanup("./foo");
}