Skip to content

Commit 3342e3f

Browse files
Modified getRelativePath function
1 parent 052cb72 commit 3342e3f

2 files changed

Lines changed: 6 additions & 10 deletions

File tree

app/inpututils.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,6 +1062,12 @@ QString InputUtils::getRelativePath( const QString &path, const QString &prefixP
10621062
const QDir prefixDir( prefixPath );
10631063
QString relativePath = prefixDir.relativeFilePath( cleanPath );
10641064

1065+
// check if the path starts with ".." or is absolute (on Windows/different drives), it's not a "child"
1066+
if ( relativePath.startsWith( QLatin1String( ".." ) ) || QDir::isAbsolutePath( relativePath ) )
1067+
{
1068+
return {};
1069+
}
1070+
10651071
if ( relativePath == cleanPath && !cleanPath.isEmpty() )
10661072
{
10671073
return {};

app/test/testutilsfunctions.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,12 +1017,7 @@ void TestUtilsFunctions::testSanitizePath()
10171017
// unchanged - url prefix
10181018
str = QStringLiteral( "file://simple/valid/filename.ext" );
10191019
InputUtils::sanitizePath( str );
1020-
1021-
#ifdef Q_OS_WIN
10221020
QCOMPARE( str, QStringLiteral( "file:///simple/valid/filename.ext" ) );
1023-
#else
1024-
QCOMPARE( str, QStringLiteral( "file://simple/valid/filename.ext" ) );
1025-
#endif
10261021

10271022
// unchanged - url prefix with slash
10281023
str = QStringLiteral( "file:///simple/valid/filename.ext" );
@@ -1042,12 +1037,7 @@ void TestUtilsFunctions::testSanitizePath()
10421037
// unchanged with partition letter on Windows and file prefix
10431038
str = QStringLiteral( "file:///C:/Users/simple/valid/filename.ext" );
10441039
InputUtils::sanitizePath( str );
1045-
1046-
#ifdef Q_OS_WIN
10471040
QCOMPARE( str, QStringLiteral( "file:///C:/Users/simple/valid/filename.ext" ) );
1048-
#else
1049-
QCOMPARE( str, QStringLiteral( "file://C:/Users/simple/valid/filename.ext" ) );
1050-
#endif
10511041

10521042
// sanitized
10531043
str = QStringLiteral( "/sa ni*tized/f<i>l?n\"a:m|e.ext " );

0 commit comments

Comments
 (0)