mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-29 22:25:04 +00:00
netops: make the path optional in URLs
When we're dealing with proxy addresses, we only want a hostname and port, and the user would not provide a path, so make it optional so we can use this same function to parse git as well as proxy URLs.
This commit is contained in:
parent
b117721dd8
commit
4e01741390
22
src/netops.c
22
src/netops.c
@ -257,16 +257,18 @@ int gitno_extract_url_parts(
|
|||||||
*port = git__strdup(default_port);
|
*port = git__strdup(default_port);
|
||||||
GITERR_CHECK_ALLOC(*port);
|
GITERR_CHECK_ALLOC(*port);
|
||||||
|
|
||||||
if (u.field_set & (1 << UF_PATH)) {
|
if (path) {
|
||||||
*path = git__substrdup(_path, u.field_data[UF_PATH].len);
|
if (u.field_set & (1 << UF_PATH)) {
|
||||||
GITERR_CHECK_ALLOC(*path);
|
*path = git__substrdup(_path, u.field_data[UF_PATH].len);
|
||||||
} else {
|
GITERR_CHECK_ALLOC(*path);
|
||||||
git__free(*port);
|
} else {
|
||||||
*port = NULL;
|
git__free(*port);
|
||||||
git__free(*host);
|
*port = NULL;
|
||||||
*host = NULL;
|
git__free(*host);
|
||||||
giterr_set(GITERR_NET, "invalid url, missing path");
|
*host = NULL;
|
||||||
return GIT_EINVALIDSPEC;
|
giterr_set(GITERR_NET, "invalid url, missing path");
|
||||||
|
return GIT_EINVALIDSPEC;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (u.field_set & (1 << UF_USERINFO)) {
|
if (u.field_set & (1 << UF_USERINFO)) {
|
||||||
|
@ -121,6 +121,15 @@ void test_network_urlparse__user_pass_port(void)
|
|||||||
cl_assert_equal_s(pass, "pass");
|
cl_assert_equal_s(pass, "pass");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void test_network_urlparse__optional_path(void)
|
||||||
|
{
|
||||||
|
cl_git_fail(gitno_extract_url_parts(&host, &port, &path, &user, &pass,
|
||||||
|
"https://user:pass@example.com:9191", "8080"));
|
||||||
|
|
||||||
|
cl_git_pass(gitno_extract_url_parts(&host, &port, NULL, &user, &pass,
|
||||||
|
"https://user:pass@example.com:9191", "8080"));
|
||||||
|
}
|
||||||
|
|
||||||
void test_network_urlparse__connection_data_http(void)
|
void test_network_urlparse__connection_data_http(void)
|
||||||
{
|
{
|
||||||
cl_git_pass(gitno_connection_data_from_url(&conndata,
|
cl_git_pass(gitno_connection_data_from_url(&conndata,
|
||||||
|
Loading…
Reference in New Issue
Block a user