diff --git a/autotests/kfilewidgettest.cpp b/autotests/kfilewidgettest.cpp --- a/autotests/kfilewidgettest.cpp +++ b/autotests/kfilewidgettest.cpp @@ -508,6 +508,33 @@ QCOMPARE(urls.size(), 1); QCOMPARE(urls[0], fileUrl); } + + void testCreateNestedNewFolders() + { + // when creating multiple nested new folders in the "save as" dialog, where folders are + //created and entered, kdirlister would hit an assert (in reinsert()), bug 408801 + const QUrl url = QUrl::fromLocalFile(QDir::tempPath()).adjusted(QUrl::StripTrailingSlash); + const QString dir = url.toLocalFile(); + KFileWidget fw(url); + fw.setOperationMode(KFileWidget::Saving); + fw.setMode(KFile::File); + fw.show(); + fw.activateWindow(); + + // create the nested folders + for (int i = 1; i < 6; ++i) { + fw.dirOperator()->mkdir(QStringLiteral("folder%1").arg(i), true); + // simulate the time the user will take to type the new folder name + QTest::qWait(1000); + } + + QVERIFY(QFile::exists(dir + QStringLiteral("/folder1/folder2/folder3/folder4/folder5"))); + // check that KFileWidget didn't crash + QVERIFY(QTest::qWaitForWindowActive(&fw)); + + // cleanup + QDir(dir + QStringLiteral("/folder1")).removeRecursively(); + } }; QTEST_MAIN(KFileWidgetTest) diff --git a/src/core/kcoredirlister_p.h b/src/core/kcoredirlister_p.h --- a/src/core/kcoredirlister_p.h +++ b/src/core/kcoredirlister_p.h @@ -305,9 +305,10 @@ DirItem *dirItem = dirItemForUrl(parentDir); if (dirItem) { auto it = std::lower_bound(dirItem->lstItems.begin(), dirItem->lstItems.end(), oldUrl); - Q_ASSERT(it != dirItem->lstItems.end()); - dirItem->lstItems.erase(it); - dirItem->insert(item); + if (it != dirItem->lstItems.end()) { + dirItem->lstItems.erase(it); + dirItem->insert(item); + } } }