FolderWizard: Don't crash when typing invalid drive #7041
authorChristian Kamm <mail@ckamm.de>
Thu, 14 Mar 2019 08:12:46 +0000 (09:12 +0100)
committerKevin Ottens <kevin.ottens@nextcloud.com>
Tue, 15 Dec 2020 09:58:49 +0000 (10:58 +0100)
When the user typed "x:" where the drive x didn't exist, the validation
function would loop forever. Now it shows a "path doesn't exist" error.

src/gui/folderman.cpp
test/testfolderman.cpp

index 3991ca4b46ad804eb0b223cac269b0da932190ba..180cebbd908ad6fc8c29f84e8743d0706c773e9e 100644 (file)
@@ -1459,7 +1459,10 @@ static QString checkPathValidityRecursive(const QString &path)
     QFileInfo selFile(path);
 
     if (!selFile.exists()) {
-        return checkPathValidityRecursive(selFile.dir().path());
+        QString parentPath = selFile.dir().path();
+        if (parentPath != path)
+            return checkPathValidityRecursive(parentPath);
+        return FolderMan::tr("The selected path does not exist!");
     }
 
     if (!selFile.isDir()) {
index 89dfe3534492798606100789d7e06f81bb3b09da..21a475327fe4fa2067b2f26cb4607cd97fbf4e82 100644 (file)
@@ -124,6 +124,19 @@ private slots:
         QVERIFY(!folderman->checkPathValidityForNewFolder("/usr/bin/somefolder").isNull());
 #endif
 
+#ifdef Q_OS_WIN // drive-letter tests
+        if (!QFileInfo("v:/").exists()) {
+            QVERIFY(!folderman->checkPathValidityForNewFolder("v:").isNull());
+            QVERIFY(!folderman->checkPathValidityForNewFolder("v:/").isNull());
+            QVERIFY(!folderman->checkPathValidityForNewFolder("v:/foo").isNull());
+        }
+        if (QFileInfo("c:/").isWritable()) {
+            QVERIFY(folderman->checkPathValidityForNewFolder("c:").isNull());
+            QVERIFY(folderman->checkPathValidityForNewFolder("c:/").isNull());
+            QVERIFY(folderman->checkPathValidityForNewFolder("c:/foo").isNull());
+        }
+#endif
+
         // Invalid paths
         QVERIFY(!folderman->checkPathValidityForNewFolder("").isNull());