summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrank Reininghaus <frank78ac@googlemail.com>2011-05-28 15:00:50 (GMT)
committerFrank Reininghaus <frank78ac@googlemail.com>2011-05-31 18:49:09 (GMT)
commitdd4ff99421fc0aa96d74bc616e64137c11862f20 (patch)
tree0aed571d18256d14e5cdd5765c06f26b9eace6ef
parent8d885c97b483b21ee13b6bf9539a1cb7e529102a (diff)
Fix crash in KDirOperator::Private::_k_slotExpandToUrl(...)
When entering '/' in the 'Name' line of the file open dialog, pressing backspace and then pasting 'a/b', where a is a subfolder of the current folder and b a file in that folder, KDirOperator may crash because it accesses a null KFileItem. This commit fixes the crash. Unit test included. BUG: 187066 FIXED-IN: 4.6.4 (cherry picked from commit 8b5c38c8d9fae85e002fae9f325277b5b200d44d)
-rw-r--r--kfile/kdiroperator.cpp2
-rw-r--r--kfile/tests/kdiroperatortest.cpp22
2 files changed, 23 insertions, 1 deletions
diff --git a/kfile/kdiroperator.cpp b/kfile/kdiroperator.cpp
index 8eb1819..4c93ac9 100644
--- a/kfile/kdiroperator.cpp
+++ b/kfile/kdiroperator.cpp
@@ -2526,7 +2526,7 @@ void KDirOperator::Private::_k_slotExpandToUrl(const QModelIndex &index)
const KUrl url = *it;
if (url.isParentOf(item.url())) {
const KFileItem _item = dirLister->findByUrl(url);
- if (_item.isDir()) {
+ if (!_item.isNull() && _item.isDir()) {
const QModelIndex _index = dirModel->indexForItem(_item);
const QModelIndex _proxyIndex = proxyModel->mapFromSource(_index);
treeView->expand(_proxyIndex);
diff --git a/kfile/tests/kdiroperatortest.cpp b/kfile/tests/kdiroperatortest.cpp
index 147aaaa..429fc30 100644
--- a/kfile/tests/kdiroperatortest.cpp
+++ b/kfile/tests/kdiroperatortest.cpp
@@ -67,6 +67,28 @@ private Q_SLOTS:
QVERIFY(qobject_cast<QTreeView*>(dirOp->view()));
delete dirOp;
}
+
+ /**
+ * testBug187066 does the following:
+ *
+ * 1. Open a KDirOperator in kdelibs/kfile
+ * 2. Set the current item to "file:///"
+ * 3. Set the current item to "file:///.../kdelibs/kfile/tests/kdiroperatortest.cpp"
+ *
+ * This may result in a crash, see https://bugs.kde.org/show_bug.cgi?id=187066
+ */
+
+ void testBug187066()
+ {
+ const KUrl kFileDirUrl(KUrl(KDESRCDIR).upUrl());
+
+ KDirOperator dirOp(kFileDirUrl);
+ dirOp.setView(KFile::DetailTree);
+ QTest::kWaitForSignal(dirOp.dirLister(), SIGNAL(completed()));
+ dirOp.setCurrentItem("file:///");
+ dirOp.setCurrentItem(KDESRCDIR "kdiroperatortest.cpp");
+ QTest::kWaitForSignal(dirOp.dirLister(), SIGNAL(completed()));
+ }
};
QTEST_KDEMAIN( KDirOperatorTest, GUI )