aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/imports/folderlistmodel/qquickfolderlistmodel.cpp12
-rw-r--r--tests/auto/qml/qquickfolderlistmodel/tst_qquickfolderlistmodel.cpp28
2 files changed, 32 insertions, 8 deletions
diff --git a/src/imports/folderlistmodel/qquickfolderlistmodel.cpp b/src/imports/folderlistmodel/qquickfolderlistmodel.cpp
index ca0739270a..2f61a9abe7 100644
--- a/src/imports/folderlistmodel/qquickfolderlistmodel.cpp
+++ b/src/imports/folderlistmodel/qquickfolderlistmodel.cpp
@@ -483,16 +483,12 @@ QUrl QQuickFolderListModel::parentFolder() const
QString localFile = d->currentDir.toLocalFile();
if (!localFile.isEmpty()) {
QDir dir(localFile);
-#if defined(Q_OS_WIN)
- if (dir.isRoot())
- dir.setPath("");
- else
-#endif
- dir.cdUp();
+ if (dir.isRoot() || !dir.cdUp())
+ return QUrl();
localFile = dir.path();
} else {
- int pos = d->currentDir.path().lastIndexOf(QLatin1Char('/'));
- if (pos == -1)
+ const int pos = d->currentDir.path().lastIndexOf(QLatin1Char('/'));
+ if (pos <= 0)
return QUrl();
localFile = d->currentDir.path().left(pos);
}
diff --git a/tests/auto/qml/qquickfolderlistmodel/tst_qquickfolderlistmodel.cpp b/tests/auto/qml/qquickfolderlistmodel/tst_qquickfolderlistmodel.cpp
index 9230608622..ef24e0a2d2 100644
--- a/tests/auto/qml/qquickfolderlistmodel/tst_qquickfolderlistmodel.cpp
+++ b/tests/auto/qml/qquickfolderlistmodel/tst_qquickfolderlistmodel.cpp
@@ -73,6 +73,7 @@ private slots:
void basicProperties();
void resetFiltering();
void refresh();
+ void cdUp();
#if defined (Q_OS_WIN) && !defined (Q_OS_WINCE)
// WinCE does not have drive concept, so lets execute this test only on desktop Windows.
void changeDrive();
@@ -182,6 +183,33 @@ void tst_qquickfolderlistmodel::refresh()
QTRY_COMPARE(removeEnd, count-1); // wait for refresh
}
+void tst_qquickfolderlistmodel::cdUp()
+{
+ enum { maxIterations = 50 };
+ QQmlComponent component(&engine, testFileUrl("basic.qml"));
+ checkNoErrors(component);
+
+ QAbstractListModel *flm = qobject_cast<QAbstractListModel*>(component.create());
+ QVERIFY(flm != 0);
+ const QUrl startFolder = flm->property("folder").toUrl();
+ QVERIFY(startFolder.isValid());
+
+ // QTBUG-32139: Ensure navigating upwards terminates cleanly and does not
+ // return invalid Urls like "file:".
+ for (int i = 0; ; ++i) {
+ const QVariant folderV = flm->property("parentFolder");
+ const QUrl folder = folderV.toUrl();
+ if (!folder.isValid())
+ break;
+ QVERIFY(folder.toString() != QLatin1String("file:"));
+ QVERIFY2(i < maxIterations,
+ qPrintable(QString::fromLatin1("Unable to reach root after %1 iterations starting from %2, stuck at %3")
+ .arg(maxIterations).arg(QDir::toNativeSeparators(startFolder.toLocalFile()),
+ QDir::toNativeSeparators(folder.toLocalFile()))));
+ flm->setProperty("folder", folderV);
+ }
+}
+
#if defined (Q_OS_WIN) && !defined (Q_OS_WINCE)
void tst_qquickfolderlistmodel::changeDrive()
{