summaryrefslogtreecommitdiffstats
path: root/src/corelib/mimetypes
diff options
context:
space:
mode:
authorEike Ziller <eike.ziller@qt.io>2018-08-18 13:08:50 +0200
committerEike Ziller <eike.ziller@qt.io>2018-08-20 07:32:58 +0000
commit67984b265a359a217c833938475a51c010057344 (patch)
tree79538cc8e0f2f2de9335a5954ce5b7a40e893834 /src/corelib/mimetypes
parentfe9a37ac4865f397533f36d1216dce6ebbacc80b (diff)
QMimeDatabase: Fix MIME detection issues with magics in MIME hierarchies
Assume two MIME types A and B are registered, both with the same glob pattern, A being parent of B, A with some magic rule, and B with another magic rule. Given a file that matches the glob pattern and the magic rule of A, the resulting MIME type depended on the order of registration of A and B, because it would just check if some glob matching MIME type was also a subclass of the magic matching MIME type. The patch prefers the the MIME type that matches by magic if that matches by glob pattern as well (i.e. A in our example). The "recommended checking order" of the spec does handle that case. Task-number: QTBUG-44846 Change-Id: I2af43f6199faf9a42cd9c35d3a045441afbd6217 Reviewed-by: Eike Ziller <eike.ziller@qt.io> Reviewed-by: David Faure <david.faure@kdab.com>
Diffstat (limited to 'src/corelib/mimetypes')
-rw-r--r--src/corelib/mimetypes/qmimedatabase.cpp7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/corelib/mimetypes/qmimedatabase.cpp b/src/corelib/mimetypes/qmimedatabase.cpp
index 68e3c8f10d..a58698af53 100644
--- a/src/corelib/mimetypes/qmimedatabase.cpp
+++ b/src/corelib/mimetypes/qmimedatabase.cpp
@@ -382,9 +382,12 @@ QMimeType QMimeDatabasePrivate::mimeTypeForFileNameAndData(const QString &fileNa
// Disambiguate conflicting extensions (if magic matching found something)
if (candidateByData.isValid() && magicAccuracy > 0) {
- // "for glob_match in glob_matches:"
- // "if glob_match is subclass or equal to sniffed_type, use glob_match"
const QString sniffedMime = candidateByData.name();
+ // If the sniffedMime matches a glob match, use it
+ if (candidatesByName.m_matchingMimeTypes.contains(sniffedMime)) {
+ *accuracyPtr = 100;
+ return candidateByData;
+ }
for (const QString &m : qAsConst(candidatesByName.m_matchingMimeTypes)) {
if (inherits(m, sniffedMime)) {
// We have magic + pattern pointing to this, so it's a pretty good match