Skip to content

Commit 938cbd0

Browse files
committed
net: handle urls with a colon after host but no port
Core git copes with URLs that have a colon after the port, but no actual numeric value. eg `http://example.com:/foo.git` or `http://example.com:`. That's horrible, but RFC 3986 says: > URI producers and normalizers should omit the port component and its > ":" delimiter if port is empty or if its value would be the same as > that of the scheme's default. Which indicates that they may and therefore we must accept it. Test that we can handle URLs with a colon but no following port number.
1 parent ff7652c commit 938cbd0

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

tests/network/urlparse.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,18 @@ void test_network_urlparse__implied_root_custom_port(void)
6161
cl_assert_equal_i(git_net_url_is_default_port(&conndata), 0);
6262
}
6363

64+
void test_network_urlparse__implied_root_empty_port(void)
65+
{
66+
cl_git_pass(git_net_url_parse(&conndata, "http://example.com:"));
67+
cl_assert_equal_s(conndata.scheme, "http");
68+
cl_assert_equal_s(conndata.host, "example.com");
69+
cl_assert_equal_s(conndata.port, "80");
70+
cl_assert_equal_s(conndata.path, "/");
71+
cl_assert_equal_p(conndata.username, NULL);
72+
cl_assert_equal_p(conndata.password, NULL);
73+
cl_assert_equal_i(git_net_url_is_default_port(&conndata), 1);
74+
}
75+
6476
void test_network_urlparse__encoded_password(void)
6577
{
6678
cl_git_pass(git_net_url_parse(&conndata,
@@ -115,6 +127,18 @@ void test_network_urlparse__port(void)
115127
cl_assert_equal_i(git_net_url_is_default_port(&conndata), 0);
116128
}
117129

130+
void test_network_urlparse__empty_port(void)
131+
{
132+
cl_git_pass(git_net_url_parse(&conndata, "http://example.com:/resource"));
133+
cl_assert_equal_s(conndata.scheme, "http");
134+
cl_assert_equal_s(conndata.host, "example.com");
135+
cl_assert_equal_s(conndata.port, "80");
136+
cl_assert_equal_s(conndata.path, "/resource");
137+
cl_assert_equal_p(conndata.username, NULL);
138+
cl_assert_equal_p(conndata.password, NULL);
139+
cl_assert_equal_i(git_net_url_is_default_port(&conndata), 1);
140+
}
141+
118142
void test_network_urlparse__user_port(void)
119143
{
120144
/* user@hostname.tld:port/resource */

0 commit comments

Comments
 (0)