From 3518a63347bef6dbc79dfef4a6a470a2dd63f1ab Mon Sep 17 00:00:00 2001 From: Magne Sjaastad Date: Wed, 2 Sep 2020 14:11:18 +0200 Subject: [PATCH] #6411 Import Ensemble : Windows-style network path not working as effective filter --- .../Application/Tools/RiaFilePathTools.cpp | 22 ++++++++++--- .../UnitTests/RiaFilePathTools-Test.cpp | 32 ++++++++++++++++++- 2 files changed, 48 insertions(+), 6 deletions(-) diff --git a/ApplicationCode/Application/Tools/RiaFilePathTools.cpp b/ApplicationCode/Application/Tools/RiaFilePathTools.cpp index 63373ad0c1..dbbcf4258a 100644 --- a/ApplicationCode/Application/Tools/RiaFilePathTools.cpp +++ b/ApplicationCode/Application/Tools/RiaFilePathTools.cpp @@ -122,12 +122,24 @@ std::pair 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; } diff --git a/ApplicationCode/UnitTests/RiaFilePathTools-Test.cpp b/ApplicationCode/UnitTests/RiaFilePathTools-Test.cpp index 4fe7a0174a..0b311c00da 100644 --- a/ApplicationCode/UnitTests/RiaFilePathTools-Test.cpp +++ b/ApplicationCode/UnitTests/RiaFilePathTools-Test.cpp @@ -81,4 +81,34 @@ TEST( RiaFilePathTools, rootSearchPathFromSearchFilter ) QString resultRootPath = RiaFilePathTools::rootSearchPathFromSearchFilter( testPath ); EXPECT_EQ( QString( "//A/B[?]/E/" ), resultRootPath ); } -} \ No newline at end of file +} + +//-------------------------------------------------------------------------------------------------- +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() ); + } +}