summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@digia.com>2012-10-26 08:44:00 (GMT)
committerThe Qt Project <gerrit-noreply@qt-project.org>2012-10-31 09:34:29 (GMT)
commit015e84b8d92ea24008341bbc71b346412d52ea48 (patch)
treed26730b21401429996dbc9d6a4aa1d10927ae264 /tests
parenta9dfa72fd199dd62f91764b4321df89ad02794bf (diff)
downloadQt-015e84b8d92ea24008341bbc71b346412d52ea48.zip
Qt-015e84b8d92ea24008341bbc71b346412d52ea48.tar.gz
Qt-015e84b8d92ea24008341bbc71b346412d52ea48.tar.bz2
Fix a crash in QFileDialog when selecting an invalid name filter.
When nameDetailsVisible is set to false and an invalid/empty string is passed to selectNameFilter(), the regexp used to strip the filter off the suffixes returns empty and a crash occurs. Change-Id: I926ea49514ff25a103977d8121fca1cf83d647f5 Reviewed-by: Miikka Heikkinen <miikka.heikkinen@digia.com> Reviewed-by: Sean Harmer <sean.harmer@kdab.com> (cherry picked from qtbase/d0aa81ee104107db1ce41a9bf0f91d4cb144f7de)
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qfiledialog/tst_qfiledialog.cpp49
1 files changed, 47 insertions, 2 deletions
diff --git a/tests/auto/qfiledialog/tst_qfiledialog.cpp b/tests/auto/qfiledialog/tst_qfiledialog.cpp
index 8e69b3c..795caf6 100644
--- a/tests/auto/qfiledialog/tst_qfiledialog.cpp
+++ b/tests/auto/qfiledialog/tst_qfiledialog.cpp
@@ -138,7 +138,9 @@ private slots:
void selectFilter();
void viewMode();
void proxymodel();
+ void setNameFilter_data();
void setNameFilter();
+ void setEmptyNameFilter();
void focus();
void caption();
void historyBack();
@@ -1019,11 +1021,54 @@ void tst_QFiledialog::proxymodel()
QCOMPARE(fd.proxyModel(), (QAbstractProxyModel*)0);
}
+void tst_QFiledialog::setEmptyNameFilter()
+{
+ QNonNativeFileDialog fd;
+ fd.setNameFilter(QString());
+ fd.setNameFilters(QStringList());
+}
+
+void tst_QFiledialog::setNameFilter_data()
+{
+ QTest::addColumn<bool>("nameFilterDetailsVisible");
+ QTest::addColumn<QStringList>("filters");
+ QTest::addColumn<QString>("selectFilter");
+ QTest::addColumn<QString>("expectedSelectedFilter");
+
+ QTest::newRow("namedetailsvisible-empty") << true << QStringList() << QString() << QString();
+ QTest::newRow("namedetailsinvisible-empty") << false << QStringList() << QString() << QString();
+
+ const QString anyFileNoDetails = QLatin1String("Any files");
+ const QString anyFile = anyFileNoDetails + QLatin1String(" (*)");
+ const QString imageFilesNoDetails = QLatin1String("Image files");
+ const QString imageFiles = imageFilesNoDetails + QLatin1String(" (*.png *.xpm *.jpg)");
+ const QString textFileNoDetails = QLatin1String("Text files");
+ const QString textFile = textFileNoDetails + QLatin1String(" (*.txt)");
+
+ QStringList filters;
+ filters << anyFile << imageFiles << textFile;
+
+ QTest::newRow("namedetailsvisible-images") << true << filters << imageFiles << imageFiles;
+ QTest::newRow("namedetailsinvisible-images") << false << filters << imageFiles << imageFilesNoDetails;
+
+ const QString invalid = "foo";
+ QTest::newRow("namedetailsvisible-invalid") << true << filters << invalid << anyFile;
+ // Potential crash when trying to convert the invalid filter into a list and stripping it, resulting in an empty list.
+ QTest::newRow("namedetailsinvisible-invalid") << false << filters << invalid << anyFileNoDetails;
+}
+
void tst_QFiledialog::setNameFilter()
{
+ QFETCH(bool, nameFilterDetailsVisible);
+ QFETCH(QStringList, filters);
+ QFETCH(QString, selectFilter);
+ QFETCH(QString, expectedSelectedFilter);
+
QNonNativeFileDialog fd;
- fd.setFilter(QString());
- fd.setFilters(QStringList());
+ fd.setNameFilters(filters);
+ fd.setNameFilterDetailsVisible(nameFilterDetailsVisible);
+ fd.selectNameFilter(selectFilter);
+ QCOMPARE(fd.selectedNameFilter(), expectedSelectedFilter);
}
void tst_QFiledialog::focus()