epee: string_tools: remove dot from get_extension

Fixes a regression introduced in #9254. Previously it did not
include the dot.
This commit is contained in:
tobtoht 2024-08-14 16:13:35 +02:00
parent 0db9e74223
commit c51ca53daa
No known key found for this signature in database
GPG key ID: E45B10DD027D2472
2 changed files with 14 additions and 1 deletions

View file

@ -178,7 +178,12 @@ namespace string_tools
std::string get_extension(const std::string& str) std::string get_extension(const std::string& str)
{ {
return boost::filesystem::path(str).extension().string(); std::string ext_with_dot = boost::filesystem::path(str).extension().string();
if (ext_with_dot.empty())
return {};
return ext_with_dot.erase(0, 1);
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------

View file

@ -1443,6 +1443,14 @@ TEST(StringTools, GetIpInt32)
EXPECT_EQ(htonl(0xff0aff00), ip); EXPECT_EQ(htonl(0xff0aff00), ip);
} }
TEST(StringTools, GetExtension)
{
EXPECT_EQ(std::string{}, epee::string_tools::get_extension(""));
EXPECT_EQ(std::string{}, epee::string_tools::get_extension("."));
EXPECT_EQ(std::string{"keys"}, epee::string_tools::get_extension("wallet.keys"));
EXPECT_EQ(std::string{"3"}, epee::string_tools::get_extension("1.2.3"));
}
TEST(NetUtils, IPv4NetworkAddress) TEST(NetUtils, IPv4NetworkAddress)
{ {
static_assert(epee::net_utils::ipv4_network_address::get_type_id() == epee::net_utils::address_type::ipv4, "bad ipv4 type id"); static_assert(epee::net_utils::ipv4_network_address::get_type_id() == epee::net_utils::address_type::ipv4, "bad ipv4 type id");