From 5f0270ae4aab06d5e58ae7205b97adc8241781f4 Mon Sep 17 00:00:00 2001 From: David Schulz Date: Thu, 25 Aug 2022 15:12:19 +0200 Subject: [PATCH] Utils: clean file name before creating fs engine Change-Id: I9c4c8132ad509820e0388787ab34bf11b3c4465b Reviewed-by: Marcus Tillmanns Reviewed-by: Reviewed-by: David Schulz --- src/libs/utils/fsengine/fsenginehandler.cpp | 5 +---- tests/auto/utils/fsengine/tst_fsengine.cpp | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/libs/utils/fsengine/fsenginehandler.cpp b/src/libs/utils/fsengine/fsenginehandler.cpp index c5aba915d35..84c9b082f87 100644 --- a/src/libs/utils/fsengine/fsenginehandler.cpp +++ b/src/libs/utils/fsengine/fsenginehandler.cpp @@ -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 diff --git a/tests/auto/utils/fsengine/tst_fsengine.cpp b/tests/auto/utils/fsengine/tst_fsengine.cpp index 48969c40176..a32575094bc 100644 --- a/tests/auto/utils/fsengine/tst_fsengine.cpp +++ b/tests/auto/utils/fsengine/tst_fsengine.cpp @@ -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"