Commit 938cbd03 by Edward Thomson

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.
parent ff7652c1
...@@ -61,6 +61,18 @@ void test_network_urlparse__implied_root_custom_port(void) ...@@ -61,6 +61,18 @@ void test_network_urlparse__implied_root_custom_port(void)
cl_assert_equal_i(git_net_url_is_default_port(&conndata), 0); cl_assert_equal_i(git_net_url_is_default_port(&conndata), 0);
} }
void test_network_urlparse__implied_root_empty_port(void)
{
cl_git_pass(git_net_url_parse(&conndata, "http://example.com:"));
cl_assert_equal_s(conndata.scheme, "http");
cl_assert_equal_s(conndata.host, "example.com");
cl_assert_equal_s(conndata.port, "80");
cl_assert_equal_s(conndata.path, "/");
cl_assert_equal_p(conndata.username, NULL);
cl_assert_equal_p(conndata.password, NULL);
cl_assert_equal_i(git_net_url_is_default_port(&conndata), 1);
}
void test_network_urlparse__encoded_password(void) void test_network_urlparse__encoded_password(void)
{ {
cl_git_pass(git_net_url_parse(&conndata, cl_git_pass(git_net_url_parse(&conndata,
...@@ -115,6 +127,18 @@ void test_network_urlparse__port(void) ...@@ -115,6 +127,18 @@ void test_network_urlparse__port(void)
cl_assert_equal_i(git_net_url_is_default_port(&conndata), 0); cl_assert_equal_i(git_net_url_is_default_port(&conndata), 0);
} }
void test_network_urlparse__empty_port(void)
{
cl_git_pass(git_net_url_parse(&conndata, "http://example.com:/resource"));
cl_assert_equal_s(conndata.scheme, "http");
cl_assert_equal_s(conndata.host, "example.com");
cl_assert_equal_s(conndata.port, "80");
cl_assert_equal_s(conndata.path, "/resource");
cl_assert_equal_p(conndata.username, NULL);
cl_assert_equal_p(conndata.password, NULL);
cl_assert_equal_i(git_net_url_is_default_port(&conndata), 1);
}
void test_network_urlparse__user_port(void) void test_network_urlparse__user_port(void)
{ {
/* user@hostname.tld:port/resource */ /* user@hostname.tld:port/resource */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment