Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2ecc858

Browse files
authored
Merge pull request libgit2#6851 from libgit2/ethomson/url_ports
2 parents d58db64 + eebaa36 commit 2ecc858

File tree

4 files changed

+113
-4
lines changed

4 files changed

+113
-4
lines changed

src/util/net.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,7 @@ static int url_parse_finalize(git_net_url *url, git_net_url_parser *parser)
387387
port = GIT_STR_INIT, path = GIT_STR_INIT,
388388
query = GIT_STR_INIT, fragment = GIT_STR_INIT;
389389
const char *default_port;
390+
int port_specified = 0;
390391
int error = 0;
391392

392393
if (parser->scheme_len) {
@@ -408,10 +409,13 @@ static int url_parse_finalize(git_net_url *url, git_net_url_parser *parser)
408409
(error = git_str_decode_percent(&host, parser->host, parser->host_len)) < 0)
409410
goto done;
410411

411-
if (parser->port_len)
412+
if (parser->port_len) {
413+
port_specified = 1;
412414
error = git_str_put(&port, parser->port, parser->port_len);
413-
else if (parser->scheme_len && (default_port = default_port_for_scheme(scheme.ptr)) != NULL)
415+
} else if (parser->scheme_len &&
416+
(default_port = default_port_for_scheme(scheme.ptr)) != NULL) {
414417
error = git_str_puts(&port, default_port);
418+
}
415419

416420
if (error < 0)
417421
goto done;
@@ -440,6 +444,7 @@ static int url_parse_finalize(git_net_url *url, git_net_url_parser *parser)
440444
url->fragment = git_str_detach(&fragment);
441445
url->username = git_str_detach(&user);
442446
url->password = git_str_detach(&password);
447+
url->port_specified = port_specified;
443448

444449
error = 0;
445450

@@ -785,10 +790,12 @@ int git_net_url_parse_scp(git_net_url *url, const char *given)
785790
GIT_ASSERT(host_len);
786791
GIT_ERROR_CHECK_ALLOC(url->host = git__strndup(host, host_len));
787792

788-
if (port_len)
793+
if (port_len) {
794+
url->port_specified = 1;
789795
GIT_ERROR_CHECK_ALLOC(url->port = git__strndup(port, port_len));
790-
else
796+
} else {
791797
GIT_ERROR_CHECK_ALLOC(url->port = git__strdup(default_port));
798+
}
792799

793800
GIT_ASSERT(path);
794801
GIT_ERROR_CHECK_ALLOC(url->path = git__strdup(path));

src/util/net.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ typedef struct git_net_url {
3535
char *fragment;
3636
char *username;
3737
char *password;
38+
39+
unsigned int port_specified;
3840
} git_net_url;
3941

4042
#define GIT_NET_URL_INIT { NULL }

0 commit comments

Comments
 (0)