Utils: clean file name before creating fs engine

Change-Id: I9c4c8132ad509820e0388787ab34bf11b3c4465b
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
David Schulz
2022-08-25 15:12:19 +02:00
parent 92c529b4a6
commit 5f0270ae4a
2 changed files with 15 additions and 4 deletions

View File

@@ -47,10 +47,7 @@ QAbstractFileEngine *FSEngineHandler::create(const QString &fileName) const
static const FilePath rootFilePath =
FilePath::specialFilePath(FilePath::SpecialPathComponent::RootPath);
QString fixedFileName = fileName;
if (fileName.startsWith("//"))
fixedFileName = fixedFileName.mid(1);
const QString fixedFileName = QDir::cleanPath(fileName);
if (fixedFileName == rootPath) {
const FilePaths paths

View File

@@ -50,6 +50,7 @@ private slots:
void testCreateDir();
void testWindowsPaths();
void testUrl();
void testBrokenWindowsPath();
private:
QString makeTestPath(QString path, bool asUrl = false);
@@ -290,5 +291,18 @@ void tst_fsengine::testUrl()
QVERIFY(p.needsDevice());
}
void tst_fsengine::testBrokenWindowsPath()
{
QTemporaryFile tmp;
QVERIFY(tmp.open());
QString localFileName = tmp.fileName();
localFileName.insert(HostOsInfo::isWindowsHost() ? 2 : 0, '/');
QFile file(localFileName);
QVERIFY(file.open(QIODevice::ReadOnly));
QCOMPARE(tmp.fileName(), QFileInfo(localFileName).canonicalFilePath());
}
QTEST_GUILESS_MAIN(tst_fsengine)
#include "tst_fsengine.moc"