diff --git a/ChangeLog b/ChangeLog index 38d4606fd..2b8e99768 100644 --- a/ChangeLog +++ b/ChangeLog @@ -78,6 +78,7 @@ 1.0.7 release + * fix IPv6 IP address resolution in URLs * introduce run-time check for torrent info-sections beeing too large * fix web seed bug when using proxy and proxy-peer-connections=false * fix bug in magnet link parser diff --git a/src/parse_url.cpp b/src/parse_url.cpp index 06c84a93c..fbee0c5b1 100644 --- a/src/parse_url.cpp +++ b/src/parse_url.cpp @@ -101,16 +101,19 @@ namespace libtorrent ec = errors::expected_close_bracket_in_address; goto exit; } + // strip the brackets + hostname.assign(start + 1, port_pos); port_pos = std::find(port_pos, url.end(), ':'); } else { port_pos = std::find(start, url.end(), ':'); + if (port_pos < end) hostname.assign(start, port_pos); + else hostname.assign(start, end); } if (port_pos < end) { - hostname.assign(start, port_pos); ++port_pos; for (std::string::iterator i = port_pos; i < end; ++i) { @@ -120,10 +123,6 @@ namespace libtorrent } port = std::atoi(std::string(port_pos, end).c_str()); } - else - { - hostname.assign(start, end); - } start = end; exit: diff --git a/test/test_http_parser.cpp b/test/test_http_parser.cpp index a7c2fb465..c26d1c8b1 100644 --- a/test/test_http_parser.cpp +++ b/test/test_http_parser.cpp @@ -403,11 +403,11 @@ TORRENT_TEST(http_parser) == make_tuple("http", "", "192.168.0.1", -1, "/path/to/file")); TEST_CHECK(parse_url_components("http://[2001:ff00::1]:42/path/to/file", ec) - == make_tuple("http", "", "[2001:ff00::1]", 42, "/path/to/file")); + == make_tuple("http", "", "2001:ff00::1", 42, "/path/to/file")); // leading spaces are supposed to be stripped TEST_CHECK(parse_url_components(" \thttp://[2001:ff00::1]:42/path/to/file", ec) - == make_tuple("http", "", "[2001:ff00::1]", 42, "/path/to/file")); + == make_tuple("http", "", "2001:ff00::1", 42, "/path/to/file")); parse_url_components("http://[2001:ff00::1:42/path/to/file", ec); TEST_CHECK(ec == error_code(errors::expected_close_bracket_in_address));