From ba64a7bb1b10ca5e0f6d2f556a07ef43962d90d1 Mon Sep 17 00:00:00 2001 From: Eike Ziller Date: Mon, 9 Mar 2015 13:20:18 +0100 Subject: [PATCH] MimeDatabase: Fix that xml files were opened in bar descriptor editor 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. Change-Id: Ia914aa7b6d0fb52f6c833897a5be69eb59fca6ab Task-number: QTBUG-44846 Reviewed-by: Daniel Teske --- src/libs/utils/mimetypes/mimedatabase.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/libs/utils/mimetypes/mimedatabase.cpp b/src/libs/utils/mimetypes/mimedatabase.cpp index 39f3cf7a2a9..be018edcc8e 100644 --- a/src/libs/utils/mimetypes/mimedatabase.cpp +++ b/src/libs/utils/mimetypes/mimedatabase.cpp @@ -190,9 +190,13 @@ MimeType MimeDatabasePrivate::mimeTypeForFileNameAndData(const QString &fileName // 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.contains(sniffedMime)) { + *accuracyPtr = 100; + return candidateByData; + } + // If there is a glob match that is a sub class of sniffedMime, use it foreach (const QString &m, candidatesByName) { if (inherits(m, sniffedMime)) { // We have magic + pattern pointing to this, so it's a pretty good match