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
QString mimeType;
const QUrl &url = q->document()->url();
QMimeDatabase db;
if (KProtocolInfo::determineMimetypeFromExtension(url.scheme())) {
mimeType = db.mimeTypeForFileNameAndData(url.fileName(), mData).name();
} else {
mimeType = db.mimeTypeForData(mData).name();
auto mime = db.mimeTypeForData(mData);
if (mime.isDefault() && KProtocolInfo::determineMimetypeFromExtension(url.scheme())) {
mime = db.mimeTypeForFileNameAndData(url.fileName(), mData);
mimeType =;
MimeTypeUtils::Kind kind = MimeTypeUtils::mimeTypeKind(mimeType);
LOG("mimeType:" << mimeType);
LOG("kind:" << kind);
  • Please, revert this patch. It causes a serious regression in functionality (breaking RAW file viewing for perfectly well filenamed images) while the benefit is very dubious.

  • mentioned in commit 1281004f

    Toggle commit list
  • Done in 1281004f.

    Sorry for the breakage and the delay.

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