diff --git a/contrib/epee/src/string_tools.cpp b/contrib/epee/src/string_tools.cpp index 4458dabdd..7ab3002b9 100644 --- a/contrib/epee/src/string_tools.cpp +++ b/contrib/epee/src/string_tools.cpp @@ -201,7 +201,12 @@ namespace string_tools 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); } //---------------------------------------------------------------------------- diff --git a/tests/unit_tests/epee_utils.cpp b/tests/unit_tests/epee_utils.cpp index d30bd3bd6..583b3642f 100644 --- a/tests/unit_tests/epee_utils.cpp +++ b/tests/unit_tests/epee_utils.cpp @@ -1427,6 +1427,14 @@ TEST(StringTools, GetIpInt32) 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) { static_assert(epee::net_utils::ipv4_network_address::get_type_id() == epee::net_utils::address_type::ipv4, "bad ipv4 type id");