Commit 78779952 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen
Browse files

utils: Fix removePath return value when path is not found

parent 1ee15d32
...@@ -151,7 +151,10 @@ std::string removePath( const std::string& fullPath, const std::string& toRemove ...@@ -151,7 +151,10 @@ std::string removePath( const std::string& fullPath, const std::string& toRemove
{ {
if ( toRemove.length() == 0 ) if ( toRemove.length() == 0 )
return fullPath; return fullPath;
auto pos = fullPath.find( toRemove ) + toRemove.length(); auto pos = fullPath.find( toRemove );
if ( pos == std::string::npos )
return fullPath;
pos += toRemove.length();
while ( fullPath[pos] == DIR_SEPARATOR while ( fullPath[pos] == DIR_SEPARATOR
#ifdef _WIN32 #ifdef _WIN32
|| fullPath[pos] == '/' || fullPath[pos] == '/'
......
...@@ -93,6 +93,7 @@ TEST( FsUtils, removePath ) ...@@ -93,6 +93,7 @@ TEST( FsUtils, removePath )
ASSERT_EQ( "bar", utils::file::removePath( "bar", "" ) ); ASSERT_EQ( "bar", utils::file::removePath( "bar", "" ) );
ASSERT_EQ( "", utils::file::removePath( "bar/", "bar" ) ); ASSERT_EQ( "", utils::file::removePath( "bar/", "bar" ) );
ASSERT_EQ( "", utils::file::removePath( "/f00/", "/f00/" ) ); ASSERT_EQ( "", utils::file::removePath( "/f00/", "/f00/" ) );
ASSERT_EQ( "/f00", utils::file::removePath( "/f00", "/path/not/found" ) );
} }
TEST( FsUtils, parentFolder ) TEST( FsUtils, parentFolder )
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment