File tree Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -178,7 +178,12 @@ namespace string_tools
178
178
179
179
std::string get_extension (const std::string& str)
180
180
{
181
- return boost::filesystem::path (str).extension ().string ();
181
+ std::string ext_with_dot = boost::filesystem::path (str).extension ().string ();
182
+
183
+ if (ext_with_dot.empty ())
184
+ return {};
185
+
186
+ return ext_with_dot.erase (0 , 1 );
182
187
}
183
188
184
189
// ----------------------------------------------------------------------------
Original file line number Diff line number Diff line change @@ -1443,6 +1443,14 @@ TEST(StringTools, GetIpInt32)
1443
1443
EXPECT_EQ (htonl (0xff0aff00 ), ip);
1444
1444
}
1445
1445
1446
+ TEST (StringTools, GetExtension)
1447
+ {
1448
+ EXPECT_EQ (std::string{}, epee::string_tools::get_extension (" " ));
1449
+ EXPECT_EQ (std::string{}, epee::string_tools::get_extension (" ." ));
1450
+ EXPECT_EQ (std::string{" keys" }, epee::string_tools::get_extension (" wallet.keys" ));
1451
+ EXPECT_EQ (std::string{" 3" }, epee::string_tools::get_extension (" 1.2.3" ));
1452
+ }
1453
+
1446
1454
TEST (NetUtils, IPv4NetworkAddress)
1447
1455
{
1448
1456
static_assert (epee::net_utils::ipv4_network_address::get_type_id () == epee::net_utils::address_type::ipv4, " bad ipv4 type id" );
You can’t perform that action at this time.
0 commit comments