Skip to content

Commit c7d4bf4

Browse files
committed
epee: string_tools: remove dot from get_extension
Fixes a regression introduced in #9254. Previously it did not include the dot.
1 parent c6d17a0 commit c7d4bf4

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

contrib/epee/src/string_tools.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,12 @@ namespace string_tools
201201

202202
std::string get_extension(const std::string& str)
203203
{
204-
return boost::filesystem::path(str).extension().string();
204+
std::string ext_with_dot = boost::filesystem::path(str).extension().string();
205+
206+
if (ext_with_dot.empty())
207+
return {};
208+
209+
return ext_with_dot.erase(0, 1);
205210
}
206211

207212
//----------------------------------------------------------------------------

tests/unit_tests/epee_utils.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1427,6 +1427,14 @@ TEST(StringTools, GetIpInt32)
14271427
EXPECT_EQ(htonl(0xff0aff00), ip);
14281428
}
14291429

1430+
TEST(StringTools, GetExtension)
1431+
{
1432+
EXPECT_EQ(std::string{}, epee::string_tools::get_extension(""));
1433+
EXPECT_EQ(std::string{}, epee::string_tools::get_extension("."));
1434+
EXPECT_EQ(std::string{"keys"}, epee::string_tools::get_extension("wallet.keys"));
1435+
EXPECT_EQ(std::string{"3"}, epee::string_tools::get_extension("1.2.3"));
1436+
}
1437+
14301438
TEST(NetUtils, IPv4NetworkAddress)
14311439
{
14321440
static_assert(epee::net_utils::ipv4_network_address::get_type_id() == epee::net_utils::address_type::ipv4, "bad ipv4 type id");

0 commit comments

Comments
 (0)