Skip to content

Commit

Permalink
Fixed bug #4 where the operator basic_string<> was not properly encod…
Browse files Browse the repository at this point in the history
…ing the port. This leads to changes where the port is now always present when we serialize the source endpoint as we derive the port from the scheme/protocol if not explicitly provided.
  • Loading branch information
abdulkareem-siddiq committed Aug 18, 2021
1 parent 5292fa2 commit c6ea2ac
Show file tree
Hide file tree
Showing 4 changed files with 594 additions and 545 deletions.
6 changes: 5 additions & 1 deletion src/SplitUri.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,11 @@ namespace siddiqsoft
/// @brief Operator rebuilds the Uri string
operator std::basic_string<CharT>() const
{
return std::format(_NORW(CharT, "{}://{}{}"), to_string<CharT>(scheme), authority.host, urlPart);
return std::format(_NORW(CharT, "{}://{}{}{}"),
to_string<CharT>(scheme),
authority.host,
(authority.port > 0) ? std::format(_NORW(CharT, ":{}"), authority.port) : _NORW(CharT, ""),
urlPart);
}


Expand Down
4 changes: 2 additions & 2 deletions tests/examples.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ namespace siddiqsoft
std::cerr << std::format("{}", u.authority) << std::endl;

// The "rebuilt" endpoint
EXPECT_EQ("https://www.google.com/search?q=siddiqsoft&from=example_1_narrow#v1", std::format("{}", u));
EXPECT_EQ("https://www.google.com:443/search?q=siddiqsoft&from=example_1_narrow#v1", std::format("{}", u));
std::cerr << std::format("{}", u) << std::endl;
}

Expand Down Expand Up @@ -135,7 +135,7 @@ namespace siddiqsoft
std::wcerr << std::format(L"{}", u.authority) << std::endl;

// The "rebuilt" endpoint
EXPECT_EQ(L"https://www.google.com/search?q=siddiqsoft&from=example_1_wide#v1", std::format(L"{}", u));
EXPECT_EQ(L"https://www.google.com:443/search?q=siddiqsoft&from=example_1_wide#v1", std::format(L"{}", u));
std::wcerr << std::format(L"{}", u) << std::endl;
}
} // namespace siddiqsoft
Loading

0 comments on commit c6ea2ac

Please sign in to comment.