Skip to content

Commit 9596a64

Browse files
committed
Merge pull request #65 from cmbrandenburg/issue_64_fix
Issue 64 fix
2 parents 1cd46a2 + 0a73332 commit 9596a64

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

src/uri.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -319,14 +319,24 @@ namespace network {
319319

320320
auto first = std::begin(*host), last = std::end(*host);
321321
auto user_info = this->user_info();
322-
if (user_info) {
322+
auto port = this->port();
323+
if (user_info && !user_info->empty()) {
323324
first = std::begin(*user_info);
325+
} else if (host->empty() && port && !port->empty()) {
326+
first = std::begin(*port);
327+
--first; // include ':' before port
324328
}
325329

326-
auto port = this->port();
327-
if (port) {
330+
if (host->empty()) {
331+
if (port && !port->empty()) {
332+
last = std::end(*port);
333+
} else if (user_info && !user_info->empty()) {
334+
last = std::end(*user_info);
335+
++last; // include '@'
336+
}
337+
} else if (port) {
328338
if (port->empty()) {
329-
++last;
339+
++last; // include ':' after host
330340
} else {
331341
last = std::end(*port);
332342
}

test/uri_builder_test.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,15 @@ TEST(builder_test, authority_with_port_test) {
698698
ASSERT_EQ("www.example.com:", *builder.uri().authority());
699699
}
700700

701+
TEST(builder_test, authority_without_host_test) {
702+
network::uri_builder builder;
703+
builder
704+
.scheme("https")
705+
.authority(":1234")
706+
;
707+
ASSERT_EQ(":1234", *builder.uri().authority());
708+
}
709+
701710
TEST(builder_test, clear_user_info_test) {
702711
network::uri instance("http://user:[email protected]:80/path?query#fragment");
703712
network::uri_builder builder(instance);

0 commit comments

Comments
 (0)