QPlatformFileDialogHelper::cleanFilterList(): Allow for ',' in glob.

RCS files (text/plain) have the glob pattern "*,v", which caused
the regular expression match to fail.

Task-number: QTBUG-47923
Change-Id: I7d8682ef51306cb4da58a2b3880842bd99892ea3
Reviewed-by: David Faure <david.faure@kdab.com>
This commit is contained in:
Friedemann Kleint 2015-08-26 15:09:50 +02:00
parent 9cdbf48c33
commit 2117a76136
2 changed files with 25 additions and 1 deletions

View File

@ -651,12 +651,13 @@ void QPlatformFileDialogHelper::setOptions(const QSharedPointer<QFileDialogOptio
}
const char *QPlatformFileDialogHelper::filterRegExp =
"^(.*)\\(([a-zA-Z0-9_.*? +;#\\-\\[\\]@\\{\\}/!<>\\$%&=^~:\\|]*)\\)$";
"^(.*)\\(([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)

View File

@ -57,6 +57,8 @@
#include "../../../../../src/widgets/dialogs/qfilesystemmodel_p.h"
#include "../../../../../src/widgets/dialogs/qfiledialog_p.h"
#include <qpa/qplatformdialoghelper.h>
#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<QString>("filterString");
QTest::addColumn<QStringList>("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"