diff --git a/scwx-qt/source/scwx/qt/util/network.cpp b/scwx-qt/source/scwx/qt/util/network.cpp index 429fac95..a0a782f8 100644 --- a/scwx-qt/source/scwx/qt/util/network.cpp +++ b/scwx-qt/source/scwx/qt/util/network.cpp @@ -25,7 +25,7 @@ std::string NormalizeUrl(const std::string& urlString) } else { - normalizedUrl = urlString; + normalizedUrl = trimmedUrlString.toStdString(); } return normalizedUrl; diff --git a/test/source/scwx/qt/util/network.test.cpp b/test/source/scwx/qt/util/network.test.cpp new file mode 100644 index 00000000..8a240ffe --- /dev/null +++ b/test/source/scwx/qt/util/network.test.cpp @@ -0,0 +1,40 @@ +#include + +#include + + + +namespace scwx +{ +namespace qt +{ +namespace util +{ + +const std::vector> 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 diff --git a/test/test.cmake b/test/test.cmake index b3cfedd2..bb36287a 100644 --- a/test/test.cmake +++ b/test/test.cmake @@ -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