Skip to content

Commit

Permalink
Fixed critical bug where the https port was not properly defaulted
Browse files Browse the repository at this point in the history
  • Loading branch information
keiichi-morisato committed Aug 5, 2021
1 parent 7ff35c7 commit 2c8ef3a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/SplitUri.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,13 @@ namespace siddiqsoft
{
posProtocol = 8;
uri.scheme = UriScheme::WebHttps;
uri.authority.port = 443; // replace later if present
}
else if (aEndpoint.starts_with(matchHttp))
{
posProtocol = 7;
uri.scheme = UriScheme::WebHttp;
uri.authority.port = 80; // replace later if present
}

if (posProtocol != std::string::npos)
Expand All @@ -245,7 +247,6 @@ namespace siddiqsoft
auto pos2 = aEndpoint.find(matchSlash, posProtocol);

// Extract the server:port portion.. make sure we don't calculate based on missing `/`
uri.authority.port = 80; // replace later if present
uri.authority.host =
aEndpoint.substr(posProtocol, pos2 != std::string::npos ? (pos2 - posProtocol) : std::string::npos);
if (auto pos3 = uri.authority.host.find(matchColon); pos3 != std::string::npos)
Expand Down
35 changes: 34 additions & 1 deletion tests/test_splituri.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ TEST(helpers_splituri, test_3)
}


TEST(helpers_splituri, test_4)
TEST(helpers_splituri, test_4a)
{
auto uri = siddiqsoft::SplitUri<std::string>("http://m.co");
EXPECT_EQ("m.co", uri.authority.host);
Expand All @@ -88,6 +88,17 @@ TEST(helpers_splituri, test_4)
}


TEST(helpers_splituri, test_4b)
{
auto uri = siddiqsoft::SplitUri<std::string>("https://m.co");
EXPECT_EQ("m.co", uri.authority.host);
EXPECT_EQ(443, uri.authority.port);
EXPECT_EQ("", uri.url);

std::cerr << "Re-serialized: " << std::string(uri) << std::endl;
}


TEST(helpers_splituri, test_5a)
{
auto uri = siddiqsoft::SplitUri<std::string>("http://<ServerName>/_vti_bin/ExcelRest.aspx/Docs/Documents/sampleWorkbook.xlsx/"
Expand Down Expand Up @@ -159,3 +170,25 @@ TEST(helpers_splituri, test_6b)
std::cerr << doc.dump(3) << std::endl;
EXPECT_EQ("questions", doc.value("/path/1"_json_pointer, ""));
}


TEST(helpers_splituri, test_6c)
{
using namespace std;

auto uri = siddiqsoft::SplitUri("https://john.doe@www.example.com/forum/questions?tag=networking&order=newest#top"s);
EXPECT_EQ("www.example.com", uri.authority.host);
EXPECT_EQ("john.doe", uri.authority.userInfo);
EXPECT_EQ(443, uri.authority.port);
EXPECT_EQ("/forum/questions?tag=networking&order=newest#top", uri.url);
EXPECT_EQ(2, uri.path.size());
EXPECT_EQ(2, uri.query.size());
EXPECT_EQ("top", uri.fragment);

std::cerr << "Re-serialized: " << std::string(uri) << std::endl;

nlohmann::json doc = uri;
EXPECT_TRUE(doc.is_object());
std::cerr << doc.dump(3) << std::endl;
EXPECT_EQ("questions", doc.value("/path/1"_json_pointer, ""));
}

0 comments on commit 2c8ef3a

Please sign in to comment.