QMimeDatabase: fix assert when fetching data for invalid mimetype

The Q_ASSERT(mimePrivate.fromCache) at qmimedatabase.cpp:218
which I added in commit 7a5644d648, was being triggered when calling comment()
for invalid mimetypes such as db.mimeTypeForName("").

Change-Id: I8037041a4b435d2a5ba24ec94b7858e38b2f0bf2
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
David Faure 2018-04-05 17:49:24 +02:00
parent e729ac6dc5
commit a1b1dd3b84
2 changed files with 4 additions and 0 deletions

View File

@ -214,6 +214,8 @@ QMimeGlobMatchResult QMimeDatabasePrivate::findByFileName(const QString &fileNam
void QMimeDatabasePrivate::loadMimeTypePrivate(QMimeTypePrivate &mimePrivate)
{
QMutexLocker locker(&mutex);
if (mimePrivate.name.isEmpty())
return; // invalid mimetype
if (!mimePrivate.loaded) { // XML provider sets loaded=true, binary provider does this on demand
Q_ASSERT(mimePrivate.fromCache);
QMimeBinaryProvider::loadMimeTypePrivate(mimePrivate);

View File

@ -214,6 +214,8 @@ void tst_QMimeDatabase::mimeTypeForName()
QMimeType doesNotExist = db.mimeTypeForName(QString::fromLatin1("foobar/x-doesnot-exist"));
QVERIFY(!doesNotExist.isValid());
QCOMPARE(doesNotExist.comment(), QString());
QCOMPARE(doesNotExist.aliases(), QStringList());
// TODO move to findByFile
#ifdef Q_OS_LINUX