Fixed issue with NormalizeUrl where whitespace trimming was not

happening on non-local files, and added test cases.
This commit is contained in:
AdenKoperczak 2024-11-25 11:42:17 -05:00
parent b5ac254259
commit b13d2106d4
3 changed files with 43 additions and 2 deletions

View file

@ -25,7 +25,7 @@ std::string NormalizeUrl(const std::string& urlString)
}
else
{
normalizedUrl = urlString;
normalizedUrl = trimmedUrlString.toStdString();
}
return normalizedUrl;

View file

@ -0,0 +1,40 @@
#include <scwx/qt/util/network.hpp>
#include <gtest/gtest.h>
namespace scwx
{
namespace qt
{
namespace util
{
const std::vector<std::pair<const std::string, const std::string>> testUrls = {
{" https://example.com/ ", "https://example.com/"},
{"\thttps://example.com/\t", "https://example.com/"},
{"\nhttps://example.com/\n", "https://example.com/"},
{"\rhttps://example.com/\r", "https://example.com/"},
{"\r\nhttps://example.com/\r\n", "https://example.com/"},
{" https://example.com/ ", "https://example.com/"},
{" \nhttps://example.com/ \n ", "https://example.com/"},
};
TEST(network, NormalizeUrl)
{
for (auto& pair : testUrls)
{
const std::string& preNormalized = pair.first;
const std::string& expNormalized = pair.second;
std::string normalized = network::NormalizeUrl(preNormalized);
EXPECT_EQ(normalized, expNormalized);
}
}
} // namespace util
} // namespace qt
} // namespace scwx

View file

@ -29,7 +29,8 @@ set(SRC_QT_MODEL_TESTS source/scwx/qt/model/imgui_context_model.test.cpp)
set(SRC_QT_SETTINGS_TESTS source/scwx/qt/settings/settings_container.test.cpp
source/scwx/qt/settings/settings_variable.test.cpp)
set(SRC_QT_UTIL_TESTS source/scwx/qt/util/q_file_input_stream.test.cpp
source/scwx/qt/util/geographic_lib.test.cpp)
source/scwx/qt/util/geographic_lib.test.cpp
source/scwx/qt/util/network.test.cpp)
set(SRC_UTIL_TESTS source/scwx/util/float.test.cpp
source/scwx/util/rangebuf.test.cpp
source/scwx/util/streams.test.cpp