From: Friedemann Kleint Date: Fri, 26 Jul 2013 12:40:09 +0000 (+0200) Subject: FolderListModel: Do not return invalid URLs like "file:" when navigating up. X-Git-Tag: upstream/5.2.1~677^2~33 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c71c7dadda2b15d7dbde6591172a1d7e85b7fbe6;p=platform%2Fupstream%2Fqtdeclarative.git FolderListModel: Do not return invalid URLs like "file:" when navigating up. Task-number: QTBUG-32139 Change-Id: I715b97eb85bc4235de6a2bb696131efae56477fd Reviewed-by: Shawn Rutledge --- diff --git a/src/imports/folderlistmodel/qquickfolderlistmodel.cpp b/src/imports/folderlistmodel/qquickfolderlistmodel.cpp index ca07392..2f61a9a 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 9230608..ef24e0a 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(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() {