#6411 Import Ensemble : Windows-style network path not working as effective filter

This commit is contained in:
Magne Sjaastad 2020-09-02 14:11:18 +02:00
parent 27ee22f420
commit 3518a63347
2 changed files with 48 additions and 6 deletions

View File

@ -122,12 +122,24 @@ std::pair<QString, QString> RiaFilePathTools::toFolderAndFileName( const QString
QString RiaFilePathTools::removeDuplicatePathSeparators( const QString& path )
{
QString correctedPath = path;
int len;
do
QString prefix;
QString doubleBackslash = R"(\\)";
if ( correctedPath.size() > 2 )
{
len = correctedPath.size();
correctedPath.replace( QString( "%1%1" ).arg( separator() ), separator() );
} while ( correctedPath.size() != len );
QString prefixCandidate = correctedPath.left( 2 );
if ( prefixCandidate == doubleBackslash || prefixCandidate == "//" )
{
prefix = prefixCandidate;
correctedPath = correctedPath.right( correctedPath.size() - 2 );
}
}
correctedPath.replace( QString( "%1%1" ).arg( separator() ), separator() );
correctedPath.replace( doubleBackslash, R"(\)" );
correctedPath = prefix + correctedPath;
return correctedPath;
}

View File

@ -81,4 +81,34 @@ TEST( RiaFilePathTools, rootSearchPathFromSearchFilter )
QString resultRootPath = RiaFilePathTools::rootSearchPathFromSearchFilter( testPath );
EXPECT_EQ( QString( "//A/B[?]/E/" ), resultRootPath );
}
}
}
//--------------------------------------------------------------------------------------------------
TEST( RiaFilePathTools, removeDuplicatePathSeparators )
{
{
QString testPath( "//myshare/folder-a/folder-b/" );
QString resultRootPath = RiaFilePathTools::removeDuplicatePathSeparators( testPath );
EXPECT_STRCASEEQ( testPath.toLatin1(), resultRootPath.toLatin1() );
}
{
QString testPath( "//myshare/folder-a//folder-b/" );
QString expectedPath( "//myshare/folder-a/folder-b/" );
QString resultRootPath = RiaFilePathTools::removeDuplicatePathSeparators( testPath );
EXPECT_STRCASEEQ( expectedPath.toLatin1(), resultRootPath.toLatin1() );
}
{
QString testPath( R"(\\myshare\folder-a\folder-b\)" );
QString resultRootPath = RiaFilePathTools::removeDuplicatePathSeparators( testPath );
EXPECT_STRCASEEQ( testPath.toLatin1(), resultRootPath.toLatin1() );
}
{
QString testPath( R"(\\myshare\folder-a\\folder-b\\)" );
QString expectedPath( R"(\\myshare\folder-a\folder-b\)" );
QString resultRootPath = RiaFilePathTools::removeDuplicatePathSeparators( testPath );
EXPECT_STRCASEEQ( expectedPath.toLatin1(), resultRootPath.toLatin1() );
}
}