Skip to content

Commit 8df6dcc

Browse files
committed
Fixed bug in getting the authority when there are parts missing.
1 parent 8d7972b commit 8df6dcc

File tree

2 files changed

+45
-4
lines changed

2 files changed

+45
-4
lines changed

boost/network/uri/uri.hpp

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -263,14 +263,49 @@ uri::string_type fragment(const uri &uri_) {
263263

264264
inline
265265
uri::string_type hierarchical_part(const uri &uri_) {
266-
return uri::string_type(boost::begin(uri_.user_info_range()),
267-
boost::end(uri_.path_range()));
266+
uri::string_type::const_iterator first, last;
267+
uri::const_range_type user_info = uri_.user_info_range();
268+
uri::const_range_type host = uri_.host_range();
269+
uri::const_range_type port = uri_.port_range();
270+
uri::const_range_type path = uri_.path_range();
271+
if (user_info) {
272+
first = boost::begin(user_info);
273+
}
274+
else {
275+
first = boost::begin(host);
276+
}
277+
if (path) {
278+
last = boost::end(path);
279+
}
280+
else if (port) {
281+
last = boost::end(port);
282+
}
283+
else {
284+
last = boost::end(host);
285+
}
286+
return uri::string_type(first, last);
268287
}
269288

270289
inline
271290
uri::string_type authority(const uri &uri_) {
272-
return uri::string_type(boost::begin(uri_.user_info_range()),
273-
boost::end(uri_.port_range()));
291+
uri::string_type::const_iterator first, last;
292+
uri::const_range_type user_info = uri_.user_info_range();
293+
uri::const_range_type host = uri_.host_range();
294+
uri::const_range_type port = uri_.port_range();
295+
if (user_info) {
296+
first = boost::begin(user_info);
297+
}
298+
else {
299+
first = boost::begin(host);
300+
}
301+
302+
if (port) {
303+
last = boost::end(port);
304+
}
305+
else {
306+
last = boost::end(host);
307+
}
308+
return uri::string_type(first, last);
274309
}
275310

276311
inline

libs/network/test/uri/uri_test.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,3 +556,9 @@ BOOST_AUTO_TEST_CASE(issue_161_test) {
556556
BOOST_CHECK_EQUAL(uri::decoded(queries["param2"]),
557557
"some plus encoded text");
558558
}
559+
560+
BOOST_AUTO_TEST_CASE(issue_364_test) {
561+
uri::uri instance;
562+
uri::schemes::http(instance) << uri::host("my.awesome.server.com");
563+
BOOST_CHECK_EQUAL("my.awesome.server.com", uri::authority(instance));
564+
}

0 commit comments

Comments
 (0)