Skip to content

Commit

Permalink
net::parseUri: rename argument url to pathAndQuery
Browse files Browse the repository at this point in the history
Signed-off-by: Méven Car <meven.car@collabora.com>
Change-Id: Ifa832978040ab1bfa156b0c639605a0e8a971324
  • Loading branch information
meven committed Dec 19, 2024
1 parent cac5bce commit 856150c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 28 deletions.
6 changes: 3 additions & 3 deletions net/NetUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ connect(std::string uri, const std::shared_ptr<ProtocolHandlerInterface>& protoc
}

bool parseUri(std::string uri, std::string& scheme, std::string& host, std::string& port,
std::string& url)
std::string& pathAndQuery)
{
const auto itScheme = uri.find("://");
if (itScheme != uri.npos)
Expand All @@ -594,12 +594,12 @@ bool parseUri(std::string uri, std::string& scheme, std::string& host, std::stri
const auto itUrl = uri.find('/');
if (itUrl != uri.npos)
{
url = uri.substr(itUrl); // Including the first foreslash.
pathAndQuery = uri.substr(itUrl); // Including the first foreslash.
uri = uri.substr(0, itUrl);
}
else
{
url.clear();
pathAndQuery.clear();
}

const auto itPort = uri.find(':');
Expand Down
6 changes: 3 additions & 3 deletions net/NetUtil.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,14 @@ connect(std::string uri, const std::shared_ptr<ProtocolHandlerInterface>& protoc
/// Decomposes a URI into its components.
/// Returns true if parsing was successful.
bool parseUri(std::string uri, std::string& scheme, std::string& host, std::string& port,
std::string& url);
std::string& pathAndQuery);

/// Decomposes a URI into its components.
/// Returns true if parsing was successful.
inline bool parseUri(std::string uri, std::string& scheme, std::string& host, std::string& port)
{
std::string url;
return parseUri(std::move(uri), scheme, host, port, url);
std::string pathAndQuery;
return parseUri(std::move(uri), scheme, host, port, pathAndQuery);
}

/// Return the locator given a URI.
Expand Down
44 changes: 22 additions & 22 deletions test/WhiteBoxTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1099,72 +1099,72 @@ void WhiteBoxTests::testParseUriUrl()
std::string scheme = "***";
std::string host = "***";
std::string port = "***";
std::string url = "***";
std::string pathAndQuery = "***";

LOK_ASSERT(!net::parseUri(std::string(), scheme, host, port, url));
LOK_ASSERT(!net::parseUri(std::string(), scheme, host, port, pathAndQuery));
LOK_ASSERT(scheme.empty());
LOK_ASSERT(host.empty());
LOK_ASSERT(port.empty());
LOK_ASSERT(url.empty());
LOK_ASSERT(pathAndQuery.empty());

LOK_ASSERT(net::parseUri("localhost", scheme, host, port, url));
LOK_ASSERT(net::parseUri("localhost", scheme, host, port, pathAndQuery));
LOK_ASSERT(scheme.empty());
LOK_ASSERT_EQUAL(std::string("localhost"), host);
LOK_ASSERT(port.empty());
LOK_ASSERT(url.empty());
LOK_ASSERT(pathAndQuery.empty());

LOK_ASSERT(net::parseUri("127.0.0.1", scheme, host, port, url));
LOK_ASSERT(net::parseUri("127.0.0.1", scheme, host, port, pathAndQuery));
LOK_ASSERT(scheme.empty());
LOK_ASSERT_EQUAL(std::string("127.0.0.1"), host);
LOK_ASSERT(port.empty());
LOK_ASSERT(url.empty());
LOK_ASSERT(pathAndQuery.empty());

LOK_ASSERT(net::parseUri("domain.com", scheme, host, port, url));
LOK_ASSERT(net::parseUri("domain.com", scheme, host, port, pathAndQuery));
LOK_ASSERT(scheme.empty());
LOK_ASSERT_EQUAL(std::string("domain.com"), host);
LOK_ASSERT(port.empty());
LOK_ASSERT(url.empty());
LOK_ASSERT(pathAndQuery.empty());

LOK_ASSERT(net::parseUri("127.0.0.1:9999", scheme, host, port, url));
LOK_ASSERT(net::parseUri("127.0.0.1:9999", scheme, host, port, pathAndQuery));
LOK_ASSERT(scheme.empty());
LOK_ASSERT_EQUAL(std::string("127.0.0.1"), host);
LOK_ASSERT_EQUAL(std::string("9999"), port);
LOK_ASSERT(url.empty());
LOK_ASSERT(pathAndQuery.empty());

LOK_ASSERT(net::parseUri("domain.com:88", scheme, host, port, url));
LOK_ASSERT(net::parseUri("domain.com:88", scheme, host, port, pathAndQuery));
LOK_ASSERT(scheme.empty());
LOK_ASSERT_EQUAL(std::string("domain.com"), host);
LOK_ASSERT_EQUAL(std::string("88"), port);
LOK_ASSERT(url.empty());
LOK_ASSERT(pathAndQuery.empty());

LOK_ASSERT(net::parseUri("http://domain.com", scheme, host, port, url));
LOK_ASSERT(net::parseUri("http://domain.com", scheme, host, port, pathAndQuery));
LOK_ASSERT_EQUAL(std::string("http://"), scheme);
LOK_ASSERT_EQUAL(std::string("domain.com"), host);
LOK_ASSERT(port.empty());
LOK_ASSERT(url.empty());
LOK_ASSERT(pathAndQuery.empty());

LOK_ASSERT(net::parseUri("https://domain.com:88", scheme, host, port, url));
LOK_ASSERT(net::parseUri("https://domain.com:88", scheme, host, port, pathAndQuery));
LOK_ASSERT_EQUAL(std::string("https://"), scheme);
LOK_ASSERT_EQUAL(std::string("domain.com"), host);
LOK_ASSERT_EQUAL(std::string("88"), port);

LOK_ASSERT(net::parseUri("http://domain.com/path/to/file", scheme, host, port, url));
LOK_ASSERT(net::parseUri("http://domain.com/path/to/file", scheme, host, port, pathAndQuery));
LOK_ASSERT_EQUAL(std::string("http://"), scheme);
LOK_ASSERT_EQUAL(std::string("domain.com"), host);
LOK_ASSERT(port.empty());
LOK_ASSERT_EQUAL(std::string("/path/to/file"), url);
LOK_ASSERT_EQUAL(std::string("/path/to/file"), pathAndQuery);

LOK_ASSERT(net::parseUri("https://domain.com:88/path/to/file", scheme, host, port, url));
LOK_ASSERT(net::parseUri("https://domain.com:88/path/to/file", scheme, host, port, pathAndQuery));
LOK_ASSERT_EQUAL(std::string("https://"), scheme);
LOK_ASSERT_EQUAL(std::string("domain.com"), host);
LOK_ASSERT_EQUAL(std::string("88"), port);
LOK_ASSERT_EQUAL(std::string("/path/to/file"), url);
LOK_ASSERT_EQUAL(std::string("/path/to/file"), pathAndQuery);

LOK_ASSERT(net::parseUri("wss://127.0.0.1:9999/", scheme, host, port, url));
LOK_ASSERT(net::parseUri("wss://127.0.0.1:9999/", scheme, host, port, pathAndQuery));
LOK_ASSERT_EQUAL(std::string("wss://"), scheme);
LOK_ASSERT_EQUAL(std::string("127.0.0.1"), host);
LOK_ASSERT_EQUAL(std::string("9999"), port);
LOK_ASSERT_EQUAL(std::string("/"), url);
LOK_ASSERT_EQUAL(std::string("/"), pathAndQuery);
}

void WhiteBoxTests::testParseUrl()
Expand Down

0 comments on commit 856150c

Please sign in to comment.