Commit 6a79391a authored by Arjen Hiemstra's avatar Arjen Hiemstra
Browse files

Prefer mime type from content over file name when loading

QMimeDatabase::mimeTypeForFileNameAndData() will prefer using the
filename for mime type determination. This allow it to be fooled when
the filename is something different than the contents. To avoid this,
reverse the logic and first try to determine the mimetype from the
file's contents and only use filename if that fails.

BUG: 329140
parent c84f6b2a
...@@ -116,11 +116,14 @@ struct LoadingDocumentImplPrivate ...@@ -116,11 +116,14 @@ struct LoadingDocumentImplPrivate
QString mimeType; QString mimeType;
const QUrl &url = q->document()->url(); const QUrl &url = q->document()->url();
QMimeDatabase db; QMimeDatabase db;
if (KProtocolInfo::determineMimetypeFromExtension(url.scheme())) {
mimeType = db.mimeTypeForFileNameAndData(url.fileName(), mData).name(); auto mime = db.mimeTypeForData(mData);
} else { if (mime.isDefault() && KProtocolInfo::determineMimetypeFromExtension(url.scheme())) {
mimeType = db.mimeTypeForData(mData).name(); mime = db.mimeTypeForFileNameAndData(url.fileName(), mData);
} }
mimeType =;
MimeTypeUtils::Kind kind = MimeTypeUtils::mimeTypeKind(mimeType); MimeTypeUtils::Kind kind = MimeTypeUtils::mimeTypeKind(mimeType);
LOG("mimeType:" << mimeType); LOG("mimeType:" << mimeType);
LOG("kind:" << kind); LOG("kind:" << kind);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment