diff --git a/src/gui/kernel/qplatformdialoghelper.cpp b/src/gui/kernel/qplatformdialoghelper.cpp index 25894fd504..20dc716d89 100644 --- a/src/gui/kernel/qplatformdialoghelper.cpp +++ b/src/gui/kernel/qplatformdialoghelper.cpp @@ -651,12 +651,13 @@ void QPlatformFileDialogHelper::setOptions(const QSharedPointer\\$%&=^~:\\|]*)\\)$"; +"^(.*)\\(([a-zA-Z0-9_.,*? +;#\\-\\[\\]@\\{\\}/!<>\\$%&=^~:\\|]*)\\)$"; // Makes a list of filters from a normal filter string "Image Files (*.png *.jpg)" QStringList QPlatformFileDialogHelper::cleanFilterList(const QString &filter) { QRegExp regexp(QString::fromLatin1(filterRegExp)); + Q_ASSERT(regexp.isValid()); QString f = filter; int i = regexp.indexIn(f); if (i >= 0) diff --git a/tests/auto/widgets/dialogs/qfiledialog2/tst_qfiledialog2.cpp b/tests/auto/widgets/dialogs/qfiledialog2/tst_qfiledialog2.cpp index ed34c67aad..85f60102a7 100644 --- a/tests/auto/widgets/dialogs/qfiledialog2/tst_qfiledialog2.cpp +++ b/tests/auto/widgets/dialogs/qfiledialog2/tst_qfiledialog2.cpp @@ -57,6 +57,8 @@ #include "../../../../../src/widgets/dialogs/qfilesystemmodel_p.h" #include "../../../../../src/widgets/dialogs/qfiledialog_p.h" +#include + #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) #include "../../../network-settings.h" #endif @@ -134,6 +136,8 @@ private slots: void QTBUG6558_showDirsOnly(); void QTBUG4842_selectFilterWithHideNameFilterDetails(); void dontShowCompleterOnRoot(); + void nameFilterParsing_data(); + void nameFilterParsing(); private: void cleanupSettingsFile(); @@ -1353,5 +1357,24 @@ void tst_QFileDialog2::dontShowCompleterOnRoot() QTRY_VERIFY(lineEdit->completer()->popup()->isHidden()); } +void tst_QFileDialog2::nameFilterParsing_data() +{ + QTest::addColumn("filterString"); + QTest::addColumn("filters"); + + // QTBUG-47923: Do not trip over "*,v". + QTest::newRow("text") << "plain text document (*.txt *.asc *,v *.doc)" + << (QStringList() << "*.txt" << "*.asc" << "*,v" << "*.doc"); + QTest::newRow("html") << "HTML document (*.html *.htm)" + << (QStringList() << "*.html" << "*.htm"); +} + +void tst_QFileDialog2::nameFilterParsing() +{ + QFETCH(QString, filterString); + QFETCH(QStringList, filters); + QCOMPARE(QPlatformFileDialogHelper::cleanFilterList(filterString), filters); +} + QTEST_MAIN(tst_QFileDialog2) #include "tst_qfiledialog2.moc"