Skip to content

Commit e277ff4

Browse files
authored
Merge pull request libgit2#5108 from libgit2/ethomson/urlparse_empty_port
Handle URLs with a colon after host but no port
2 parents 0c1029b + fb529a0 commit e277ff4

File tree

5 files changed

+53
-8
lines changed

5 files changed

+53
-8
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ OPTION(USE_HTTPS "Enable HTTPS support. Can be set to a specific backend" ON)
6060
OPTION(USE_GSSAPI "Link with libgssapi for SPNEGO auth" OFF)
6161
OPTION(USE_STANDALONE_FUZZERS "Enable standalone fuzzers (compatible with gcc)" OFF)
6262
OPTION(VALGRIND "Configure build for valgrind" OFF)
63-
OPTION(USE_EXT_HTTP_PARSER "Use system HTTP_Parser if available" ON)
6463
OPTION(DEBUG_POOL "Enable debug pool allocator" OFF)
6564
OPTION(ENABLE_WERROR "Enable compilation with -Werror" OFF)
6665
OPTION(USE_BUNDLED_ZLIB "Use the bundled version of zlib" OFF)
66+
SET(USE_HTTP_PARSER "" CACHE STRING "Specifies the HTTP Parser implementation; either system or builtin.")
6767
OPTION(DEPRECATE_HARD "Do not include deprecated functions in the library" OFF)
6868
SET(REGEX_BACKEND "" CACHE STRING "Regular expression implementation. One of regcomp_l, pcre2, pcre, regcomp, or builtin.")
6969

deps/http-parser/http_parser.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2047,7 +2047,6 @@ http_parse_host(const char * buf, struct http_parser_url *u, int found_at) {
20472047
case s_http_host_start:
20482048
case s_http_host_v6_start:
20492049
case s_http_host_v6:
2050-
case s_http_host_port_start:
20512050
case s_http_userinfo:
20522051
case s_http_userinfo_start:
20532052
return 1;

docs/changelog.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
v0.28 + 1
2+
---------
3+
4+
### Breaking CMake configuration changes
5+
6+
* The CMake option to use a system http-parser library, instead of the
7+
bundled dependency, has changed. This is due to a deficiency in
8+
http-parser that we have fixed in our implementation. The bundled
9+
library is now the default, but if you wish to force the use of the
10+
system http-parser implementation despite incompatibilities, you can
11+
specify `-DUSE_HTTP_PARSER=system` to CMake.
12+
13+
### Changes or improvements
14+
15+
* libgit2 can now correctly cope with URLs where the host contains a colon
16+
but a port is not specified. (eg `http://example.com:/repo.git`).
17+
118
v0.28
219
-----
320

src/CMakeLists.txt

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -340,12 +340,17 @@ ELSE()
340340
ENDIF()
341341

342342
# Optional external dependency: http-parser
343-
FIND_PACKAGE(HTTP_Parser)
344-
IF (USE_EXT_HTTP_PARSER AND HTTP_PARSER_FOUND AND HTTP_PARSER_VERSION_MAJOR EQUAL 2)
345-
LIST(APPEND LIBGIT2_SYSTEM_INCLUDES ${HTTP_PARSER_INCLUDE_DIRS})
346-
LIST(APPEND LIBGIT2_LIBS ${HTTP_PARSER_LIBRARIES})
347-
LIST(APPEND LIBGIT2_PC_LIBS "-lhttp_parser")
348-
ADD_FEATURE_INFO(http-parser ON "http-parser support")
343+
IF(USE_HTTP_PARSER STREQUAL "system")
344+
FIND_PACKAGE(HTTP_Parser)
345+
346+
IF (HTTP_PARSER_FOUND AND HTTP_PARSER_VERSION_MAJOR EQUAL 2)
347+
LIST(APPEND LIBGIT2_SYSTEM_INCLUDES ${HTTP_PARSER_INCLUDE_DIRS})
348+
LIST(APPEND LIBGIT2_LIBS ${HTTP_PARSER_LIBRARIES})
349+
LIST(APPEND LIBGIT2_PC_LIBS "-lhttp_parser")
350+
ADD_FEATURE_INFO(http-parser ON "http-parser support (system)")
351+
ELSE()
352+
MESSAGE(FATAL_ERROR "http-parser support was requested but not found")
353+
ENDIF()
349354
ELSE()
350355
MESSAGE(STATUS "http-parser version 2 was not found or disabled; using bundled 3rd-party sources.")
351356
ADD_SUBDIRECTORY("${libgit2_SOURCE_DIR}/deps/http-parser" "${libgit2_BINARY_DIR}/deps/http-parser")

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)